Wiki source code of Intersection table of ML Elements with glossary terms
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
3.2 | 1 | {{velocity}} |
| |
1.1 | 2 | #set($rootDocFullName = $doc.getParent()) |
| 3 | #set($rootDoc = $xwiki.getDocument($rootDocFullName)) | ||
| 4 | #set($fullNamePrefix = "${rootDoc.space}.%") | ||
| |
3.2 | 5 | |
| |
1.1 | 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") | ||
| |
3.2 | 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 | |||
| |
1.1 | 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()) | ||
| |
3.2 | 38 | |
| |
1.1 | 39 | ## --------------------------- |
| 40 | ## 3. Строим map глоссария по нормализованному title | ||
| 41 | ## ---------------------------- | ||
| 42 | #set($glossaryMap = {}) | ||
| |
3.2 | 43 | |
| |
1.1 | 44 | #foreach($row in $glossaryRows) |
| 45 | #set($glossaryFullName = $row[0]) | ||
| 46 | #set($glossaryTitle = "$!row[1]") | ||
| 47 | |||
| 48 | #if("$!glossaryTitle" != "") | ||
| |
3.2 | 49 | #set($normalizedGlossaryTitle = $stringtool.lowerCase($glossaryTitle).replaceAll("\\s+", "")) |
| |
1.1 | 50 | |
| 51 | #if("$!normalizedGlossaryTitle" != "") | ||
| 52 | #set($discard = $glossaryMap.put($normalizedGlossaryTitle, { | ||
| 53 | "fullName" : $glossaryFullName, | ||
| 54 | "title" : $glossaryTitle | ||
| 55 | })) | ||
| 56 | #end | ||
| 57 | #end | ||
| 58 | #end | ||
| |
3.2 | 59 | |
| |
1.1 | 60 | ## ---------------------------- |
| |
3.2 | 61 | ## 4. Ищем совпадения и записываем rdfs.seeAlso |
| |
1.1 | 62 | ## ---------------------------- |
| 63 | #set($matches = []) | ||
| |
3.2 | 64 | #set($updatedCount = 0) |
| |
1.1 | 65 | |
| 66 | #foreach($row in $elementRows) | ||
| 67 | #set($elementFullName = $row[0]) | ||
| 68 | #set($elementTitle = "$!row[1]") | ||
| 69 | |||
| 70 | #if("$!elementTitle" != "") | ||
| |
3.2 | 71 | #set($normalizedElementTitle = $stringtool.lowerCase($elementTitle).replaceAll("\\s+", "")) |
| |
1.1 | 72 | |
| 73 | #if($glossaryMap.containsKey($normalizedElementTitle)) | ||
| 74 | #set($glossaryData = $glossaryMap.get($normalizedElementTitle)) | ||
| 75 | |||
| |
3.2 | 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 | |||
| |
1.1 | 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 | ||
| |
3.2 | 98 | |
| |
1.1 | 99 | ## --------------------------- |
| |
3.2 | 100 | ## 5. Выводим результат |
| |
1.1 | 101 | ## ---------------------------- |
| 102 | {{html clean="false" wiki="true"}} | ||
| |
3.2 | 103 | <p><strong>Updated:</strong> $updatedCount</p> |
| 104 | |||
| |
1.1 | 105 | <table class="wikitable" border="1"> |
| 106 | <thead> | ||
| 107 | <tr> | ||
| |
3.2 | 108 | <th>Ontology elements</th> |
| 109 | <th>Written to rdfs.seeAlso</th> | ||
| |
1.1 | 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}} |