Skip to content

Commit 659efbb

Browse files
committed
First simplistic approach to find more specific categories for templates (use any subcategory)
1 parent dea9fb6 commit 659efbb

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

main.go

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,15 @@ func (p *TripleAggregateToWikiPageConverter) Run() {
470470

471471
pageTitle, _ := p.convertUriToWikiTitle(aggr.SubjectStr, pageType, resourceIndex)
472472

473-
page := NewWikiPage(pageTitle, []*Fact{}, []string{}, pageType)
473+
page := NewWikiPage(pageTitle, []*Fact{}, []string{}, "", pageType)
474474

475475
for _, tr := range aggr.Triples {
476476

477477
predTitle, propertyStr := p.convertUriToWikiTitle(tr.Pred.String(), URITypePredicate, resourceIndex) // Here we know it is a predicate, simply because its location in a triple
478478

479479
// Make sure property page exists
480480
if predPageIndex[predTitle] == nil {
481-
predPageIndex[predTitle] = NewWikiPage(predTitle, []*Fact{}, []string{}, URITypePredicate)
481+
predPageIndex[predTitle] = NewWikiPage(predTitle, []*Fact{}, []string{}, "", URITypePredicate)
482482
}
483483

484484
var valueStr string
@@ -516,6 +516,17 @@ func (p *TripleAggregateToWikiPageConverter) Run() {
516516

517517
if tr.Pred.String() == typePropertyURI || tr.Pred.String() == subClassPropertyURI {
518518
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+
}
528+
}
529+
519530
} else {
520531
page.AddFactUnique(NewFact(propertyStr, valueStr))
521532
}
@@ -734,7 +745,13 @@ func (p *MWXMLCreator) Run() {
734745

735746
if p.UseTemplates && len(page.Categories) > 0 { // We need at least one category, as to name the (to-be) template
736747

737-
templateName := page.Categories[0]
748+
var templateName string
749+
if page.SpecificCategory != "" {
750+
templateName = page.SpecificCategory
751+
} else {
752+
// Pick last item (biggest chance to be pretty specific?)
753+
templateName = page.Categories[len(page.Categories)-1]
754+
}
738755
templateTitle := "Template:" + templateName
739756

740757
// Make sure template page exists
@@ -1003,18 +1020,20 @@ func NewTripleAggregate(subj rdf.Subject, triples []rdf.Triple) *TripleAggregate
10031020
// --------------------------------------------------------------------------------
10041021

10051022
type WikiPage struct {
1006-
Title string
1007-
Type int
1008-
Facts []*Fact
1009-
Categories []string
1023+
Title string
1024+
Type int
1025+
Facts []*Fact
1026+
Categories []string
1027+
SpecificCategory string
10101028
}
10111029

1012-
func NewWikiPage(title string, facts []*Fact, categories []string, pageType int) *WikiPage {
1030+
func NewWikiPage(title string, facts []*Fact, categories []string, specificCategory string, pageType int) *WikiPage {
10131031
return &WikiPage{
1014-
Title: title,
1015-
Facts: facts,
1016-
Categories: categories,
1017-
Type: pageType,
1032+
Title: title,
1033+
Facts: facts,
1034+
Categories: categories,
1035+
SpecificCategory: specificCategory,
1036+
Type: pageType,
10181037
}
10191038
}
10201039

0 commit comments

Comments
 (0)