Skip to content

Commit

Permalink
First simplistic approach to find more specific categories for templa…
Browse files Browse the repository at this point in the history
…tes (use any subcategory)
  • Loading branch information
samuell committed Aug 17, 2016
1 parent dea9fb6 commit 659efbb
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,15 @@ func (p *TripleAggregateToWikiPageConverter) Run() {

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

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

for _, tr := range aggr.Triples {

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

// Make sure property page exists
if predPageIndex[predTitle] == nil {
predPageIndex[predTitle] = NewWikiPage(predTitle, []*Fact{}, []string{}, URITypePredicate)
predPageIndex[predTitle] = NewWikiPage(predTitle, []*Fact{}, []string{}, "", URITypePredicate)
}

var valueStr string
Expand Down Expand Up @@ -516,6 +516,17 @@ func (p *TripleAggregateToWikiPageConverter) Run() {

if tr.Pred.String() == typePropertyURI || tr.Pred.String() == subClassPropertyURI {
page.AddCategoryUnique(valueStr)

// Check if the category is a subcategory of another one, and if so, store separately
catPage := (*resourceIndex)[tr.Obj.String()]
if catPage != nil {
for _, subTr := range catPage.Triples {
if subTr.Pred.String() == typePropertyURI || subTr.Pred.String() == subClassPropertyURI {
page.SpecificCategory = valueStr
}
}
}

} else {
page.AddFactUnique(NewFact(propertyStr, valueStr))
}
Expand Down Expand Up @@ -734,7 +745,13 @@ func (p *MWXMLCreator) Run() {

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

templateName := page.Categories[0]
var templateName string
if page.SpecificCategory != "" {
templateName = page.SpecificCategory
} else {
// Pick last item (biggest chance to be pretty specific?)
templateName = page.Categories[len(page.Categories)-1]
}
templateTitle := "Template:" + templateName

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

type WikiPage struct {
Title string
Type int
Facts []*Fact
Categories []string
Title string
Type int
Facts []*Fact
Categories []string
SpecificCategory string
}

func NewWikiPage(title string, facts []*Fact, categories []string, pageType int) *WikiPage {
func NewWikiPage(title string, facts []*Fact, categories []string, specificCategory string, pageType int) *WikiPage {
return &WikiPage{
Title: title,
Facts: facts,
Categories: categories,
Type: pageType,
Title: title,
Facts: facts,
Categories: categories,
SpecificCategory: specificCategory,
Type: pageType,
}
}

Expand Down

0 comments on commit 659efbb

Please sign in to comment.