Wiki source code of Intersection table of ML Elements with glossary terms
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{velocity}} | ||
| 2 | #set($rootDocFullName = $doc.getParent()) | ||
| 3 | #set($rootDoc = $xwiki.getDocument($rootDocFullName)) | ||
| 4 | #set($fullNamePrefix = "${rootDoc.space}.%") | ||
| 5 | |||
| 6 | ## ---------------------------- | ||
| 7 | ## 1. Получаем Ontology Elements | ||
| 8 | ## ---------------------------- | ||
| 9 | #set($hqlElements = "select distinct | ||
| 10 | doc.fullName, | ||
| 11 | doc.title | ||
| 12 | from XWikiDocument as doc, | ||
| 13 | BaseObject as obj | ||
| 14 | where doc.fullName = obj.name | ||
| 15 | and obj.className = 'SKMS.Ontology.Code.OntologyElementClass' | ||
| 16 | and doc.fullName <> :rootDocFullName | ||
| 17 | and doc.fullName like :fullNamePrefix | ||
| 18 | order by doc.fullName") | ||
| 19 | |||
| 20 | #set($elementQuery = $services.query.hql($hqlElements)) | ||
| 21 | #set($discard = $elementQuery.bindValue('rootDocFullName', $rootDocFullName)) | ||
| 22 | #set($discard = $elementQuery.bindValue('fullNamePrefix', $fullNamePrefix)) | ||
| 23 | #set($elementRows = $elementQuery.execute()) | ||
| 24 | |||
| 25 | ## --------------------------- | ||
| 26 | ## 2. Получаем термины глоссария | ||
| 27 | ## ---------------------------- | ||
| 28 | #set($hqlGlossary = "select distinct | ||
| 29 | doc.fullName, | ||
| 30 | doc.title | ||
| 31 | from XWikiDocument as doc, | ||
| 32 | BaseObject as obj | ||
| 33 | where doc.fullName = obj.name | ||
| 34 | and obj.className = 'SKMS.Glossary.Code.GlossaryConceptClass' | ||
| 35 | order by doc.fullName") | ||
| 36 | |||
| 37 | #set($glossaryRows = $services.query.hql($hqlGlossary).execute()) | ||
| 38 | |||
| 39 | ## --------------------------- | ||
| 40 | ## 3. Строим map глоссария по нормализованному title | ||
| 41 | ## ---------------------------- | ||
| 42 | #set($glossaryMap = {}) | ||
| 43 | |||
| 44 | #foreach($row in $glossaryRows) | ||
| 45 | #set($glossaryFullName = $row[0]) | ||
| 46 | #set($glossaryTitle = "$!row[1]") | ||
| 47 | |||
| 48 | #if("$!glossaryTitle" != "") | ||
| 49 | #set($normalizedGlossaryTitle = $stringtool.lowerCase($glossaryTitle).replaceAll("\\s+", "")) | ||
| 50 | |||
| 51 | #if("$!normalizedGlossaryTitle" != "") | ||
| 52 | #set($discard = $glossaryMap.put($normalizedGlossaryTitle, { | ||
| 53 | "fullName" : $glossaryFullName, | ||
| 54 | "title" : $glossaryTitle | ||
| 55 | })) | ||
| 56 | #end | ||
| 57 | #end | ||
| 58 | #end | ||
| 59 | |||
| 60 | ## ---------------------------- | ||
| 61 | ## 4. Ищем совпадения и записываем rdfs.seeAlso | ||
| 62 | ## ---------------------------- | ||
| 63 | #set($matches = []) | ||
| 64 | #set($updatedCount = 0) | ||
| 65 | |||
| 66 | #foreach($row in $elementRows) | ||
| 67 | #set($elementFullName = $row[0]) | ||
| 68 | #set($elementTitle = "$!row[1]") | ||
| 69 | |||
| 70 | #if("$!elementTitle" != "") | ||
| 71 | #set($normalizedElementTitle = $stringtool.lowerCase($elementTitle).replaceAll("\\s+", "")) | ||
| 72 | |||
| 73 | #if($glossaryMap.containsKey($normalizedElementTitle)) | ||
| 74 | #set($glossaryData = $glossaryMap.get($normalizedElementTitle)) | ||
| 75 | |||
| 76 | #set($rdoc = $xwiki.getDocument($elementFullName)) | ||
| 77 | #set($elementObj = $rdoc.getObject('SKMS.Ontology.Code.OntologyElementClass')) | ||
| 78 | |||
| 79 | #set($seeAlsoValue = []) | ||
| 80 | #set($discard = $seeAlsoValue.add($glossaryData.fullName)) | ||
| 81 | |||
| 82 | #set($discard = $elementObj.set('rdfs.seeAlso', $seeAlsoValue)) | ||
| 83 | #set($discard = $rdoc.save()) | ||
| 84 | |||
| 85 | #set($updatedCount = $updatedCount + 1) | ||
| 86 | |||
| 87 | #set($matchRow = { | ||
| 88 | "elementFullName" : $elementFullName, | ||
| 89 | "elementTitle" : $elementTitle, | ||
| 90 | "glossaryFullName" : $glossaryData.fullName, | ||
| 91 | "glossaryTitle" : $glossaryData.title | ||
| 92 | }) | ||
| 93 | |||
| 94 | #set($discard = $matches.add($matchRow)) | ||
| 95 | #end | ||
| 96 | #end | ||
| 97 | #end | ||
| 98 | |||
| 99 | ## --------------------------- | ||
| 100 | ## 5. Выводим результат | ||
| 101 | ## ---------------------------- | ||
| 102 | {{html clean="false" wiki="true"}} | ||
| 103 | <p><strong>Updated:</strong> $updatedCount</p> | ||
| 104 | |||
| 105 | <table class="wikitable" border="1"> | ||
| 106 | <thead> | ||
| 107 | <tr> | ||
| 108 | <th>Ontology elements</th> | ||
| 109 | <th>Written to rdfs.seeAlso</th> | ||
| 110 | </tr> | ||
| 111 | </thead> | ||
| 112 | <tbody> | ||
| 113 | #if($matches.size() > 0) | ||
| 114 | #foreach($match in $matches) | ||
| 115 | <tr> | ||
| 116 | <td>[[${match.elementTitle}>>${match.elementFullName}||target="_blank"]]</td> | ||
| 117 | <td>[[${match.glossaryTitle}>>${match.glossaryFullName}||target="_blank"]]</td> | ||
| 118 | </tr> | ||
| 119 | #end | ||
| 120 | #else | ||
| 121 | <tr> | ||
| 122 | <td colspan="2">No matches found.</td> | ||
| 123 | </tr> | ||
| 124 | #end | ||
| 125 | </tbody> | ||
| 126 | </table> | ||
| 127 | {{/html}} | ||
| 128 | {{/velocity}} |