@@ -472,6 +472,7 @@ func (p *TripleAggregateToWikiPageConverter) Run() {
472472
473473 page := NewWikiPage (pageTitle , []* Fact {}, []string {}, "" , pageType )
474474
475+ topSuperCatsCnt := 0
475476 for _ , tr := range aggr .Triples {
476477
477478 predTitle , propertyStr := p .convertUriToWikiTitle (tr .Pred .String (), URITypePredicate , resourceIndex ) // Here we know it is a predicate, simply because its location in a triple
@@ -516,17 +517,12 @@ func (p *TripleAggregateToWikiPageConverter) Run() {
516517
517518 if tr .Pred .String () == typePropertyURI || tr .Pred .String () == subClassPropertyURI {
518519 page .AddCategoryUnique (valueStr )
519-
520- // Check if the category is a subcategory of another one, and if so, store separately
521- catPage := (* resourceIndex )[tr .Obj .String ()]
522- if catPage != nil {
523- for _ , subTr := range catPage .Triples {
524- if subTr .Pred .String () == typePropertyURI || subTr .Pred .String () == subClassPropertyURI {
525- page .SpecificCategory = valueStr
526- }
527- }
520+ superCatsCnt := countSuperCategories (tr , resourceIndex )
521+ if superCatsCnt > topSuperCatsCnt {
522+ topSuperCatsCnt = superCatsCnt
523+ page .SpecificCategory = valueStr
524+ //println("Page:", page.Title, " | Adding cat", valueStr, "since has", superCatsCnt, "super categories.")
528525 }
529-
530526 } else {
531527 page .AddFactUnique (NewFact (propertyStr , valueStr ))
532528 }
@@ -751,6 +747,7 @@ func (p *MWXMLCreator) Run() {
751747 } else {
752748 // Pick last item (biggest chance to be pretty specific?)
753749 templateName = page .Categories [len (page .Categories )- 1 ]
750+ //println("Page ", page.Title, " | Didn't have a specific catogory, so selected ", templateName)
754751 }
755752 templateTitle := "Template:" + templateName
756753
@@ -1131,3 +1128,19 @@ func escapeWikiChars(inStr string) string {
11311128 outStr = str .Replace (outStr , ">" , ">" , - 1 )
11321129 return outStr
11331130}
1131+
1132+ func countSuperCategories (tr rdf.Triple , ri * map [string ]* TripleAggregate ) int {
1133+ catPage := (* ri )[tr .Obj .String ()]
1134+ topSuperCatsCnt := 0
1135+ if catPage != nil {
1136+ for _ , subTr := range catPage .Triples {
1137+ if subTr .Pred .String () == typePropertyURI || subTr .Pred .String () == subClassPropertyURI {
1138+ superCatsCnt := countSuperCategories (subTr , ri ) + 1
1139+ if superCatsCnt > topSuperCatsCnt {
1140+ topSuperCatsCnt = superCatsCnt
1141+ }
1142+ }
1143+ }
1144+ }
1145+ return topSuperCatsCnt
1146+ }
0 commit comments