Skip to content

Commit 72f6436

Browse files
committed
update OntologyReader to get Wikidata Sameas properties and map wikidata URI triples
1 parent 80fdc9e commit 72f6436

File tree

5 files changed

+61
-14460
lines changed

5 files changed

+61
-14460
lines changed

core/src/main/scala/org/dbpedia/extraction/mappings/WikidataFactsExtractor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.dbpedia.extraction.mappings
22

3-
import org.dbpedia.extraction.ontology.Ontology
3+
import org.dbpedia.extraction.ontology._
44
import org.dbpedia.extraction.util.Language
55
import org.dbpedia.extraction.destinations.{Quad, DBpediaDatasets}
66
import org.dbpedia.extraction.wikiparser.{SimpleNode, PageNode}

core/src/main/scala/org/dbpedia/extraction/mappings/WikidataMappedFactsExtractor.scala

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.dbpedia.extraction.util.Language
55
import org.dbpedia.extraction.destinations.{Quad, DBpediaDatasets}
66
import org.dbpedia.extraction.wikiparser.{SimpleNode, PageNode}
77
import collection.mutable.ArrayBuffer
8+
import org.dbpedia.extraction.ontology.io.OntologyReader
89

910
/**
1011
* Extracts Wikidata claims
@@ -49,17 +50,15 @@ class WikidataMappedFactsExtractor(
4950
//Generating Quads for ValueTriples
5051
for (property <- node.getValueTriples.keys)
5152
{
52-
5353
//check for triples that doesn't contain Label or sameas properties only
54-
if(property != "http://www.w3.org/2000/01/rdf-schema#label" && property != "http://www.w3.org/2002/07/owl#sameAs" ){
55-
56-
val valueFacts = node.getValueTriples(property)
57-
for( fact <- valueFacts.keys)
58-
{
59-
quads += new Quad(Language.apply("en"), DBpediaDatasets.WikidataFacts, subjectUri, property ,fact , page.sourceUri, context.ontology.datatypes("xsd:string"))
60-
}
61-
62-
}
54+
// if(property != "http://www.w3.org/2000/01/rdf-schema#label" && property != "http://www.w3.org/2002/07/owl#sameAs" ){
55+
//
56+
// val valueFacts = node.getValueTriples(property)
57+
// for( fact <- valueFacts.keys)
58+
// {
59+
// quads += new Quad(Language.apply("en"), DBpediaDatasets.WikidataFacts, subjectUri, property ,fact , page.sourceUri, context.ontology.datatypes("xsd:string"))
60+
// }
61+
// }
6362
}
6463

6564
//Generating Quads for Uri
@@ -72,21 +71,28 @@ class WikidataMappedFactsExtractor(
7271
val UriFacts = node.getUriTriples(property)
7372
for( fact <- UriFacts)
7473
{
75-
//println(subjectUri+"\t"+property+"\t"+fact)
76-
quads += new Quad(Language.apply("en"), DBpediaDatasets.WikidataFacts, subjectUri, property,fact , page.sourceUri,null)
74+
//print(context.ontology.equivalentPropertiesMap.size)
75+
76+
context.ontology.equivalentPropertiesMap.foreach({map =>
77+
if (map._1.toString.matches(property))
78+
{
79+
map._2.foreach{mappedProp =>
80+
quads += new Quad(Language.apply("en"), DBpediaDatasets.WikidataFacts, subjectUri, mappedProp.toString,fact , page.sourceUri,null)
81+
}
82+
}
83+
})
7784
}
7885
}
7986
}
80-
81-
82-
8387
}
8488

85-
case _=>
89+
case _ =>
8690

8791
}
8892
}
8993

9094
quads
9195
}
9296
}
97+
98+

core/src/main/scala/org/dbpedia/extraction/ontology/io/OntologyReader.scala

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class OntologyReader
2525
/**
2626
* Loads an ontology from configuration files using the DBpedia mapping language.
2727
*
28-
* @param source The source containing the ontology pages
28+
* @param pageNodeSource The source containing the ontology pages
2929
* @return Ontology The ontology
3030
*/
3131
def read(pageNodeSource : Traversable[PageNode]) : Ontology =
@@ -57,8 +57,8 @@ class OntologyReader
5757
/**
5858
* Loads all classes and properties from a page.
5959
*
60-
* @param ontology The OntologyBuilder instance
61-
* @param pageNode The page node of the configuration page
60+
* @param ontologyBuilder The OntologyBuilder instance
61+
* @param page The page node of the configuration page
6262
*/
6363
private def load(ontologyBuilder : OntologyBuilder, page : PageNode)
6464
{
@@ -76,8 +76,8 @@ class OntologyReader
7676

7777
for(specificProperty <- loadSpecificProperties(name, templateNode))
7878
{
79+
7980
ontologyBuilder.specializedProperties ::= specificProperty
80-
// To check for equivalent Property Map
8181
}
8282
}
8383
else if(templateName == OntologyReader.OBJECTPROPERTY_NAME || templateName == OntologyReader.DATATYPEPROPERTY_NAME)
@@ -86,11 +86,30 @@ class OntologyReader
8686

8787
for(property <- loadOntologyProperty(name, templateNode))
8888
{
89-
ontologyBuilder.properties ::= property
90-
// Fill the equivalentProperty map
89+
ontologyBuilder.properties ::= property
90+
91+
92+
//add mappings to equivalentPropertiesBuilderMap in the form of WikidataProp -> Set[equivalentDBprop]
93+
property.equivPropertyNames.foreach{prop =>
94+
95+
if(prop.contains("wikidata:")){
96+
97+
//search for wikidataprop in the equivalentPropertiesBuilderMap keys if exists add DBprop to the set of DBprop
98+
// if not create new key
99+
ontologyBuilder.equivalentPropertiesBuilderMap.find{map => map._1.name == prop} match {
100+
101+
case Some(map) => ontologyBuilder.equivalentPropertiesBuilderMap.updated(map._1 ,property)
102+
case None => {
103+
val wikidataProp = new OntologyProperty(prop, Map(), Map(), null, null, false, Set())
104+
ontologyBuilder.equivalentPropertiesBuilderMap += wikidataProp -> Set(property)
105+
}
106+
}
107+
108+
}
109+
}
110+
91111
}
92112
}
93-
// TODO: read datatypes
94113
}
95114
}
96115

@@ -99,7 +118,7 @@ class OntologyReader
99118
* A namespace like "Foaf:" is always converted to lowercase. The local name (the part
100119
* after the namespace prefix) is cleaned using the given function.
101120
*
102-
* @param name page title
121+
* @param title page title
103122
* @param clean used to process the local name
104123
* @return clean name, including lower-case namespace and clean local name
105124
* @throws IllegalArgumentException
@@ -301,20 +320,28 @@ class OntologyReader
301320
var properties = List[PropertyBuilder]()
302321
var datatypes = List[Datatype]()
303322
var specializedProperties = List[SpecificPropertyBuilder]()
304-
var equivalentPropertiesMap = Map[OntologyProperty,Set[OntologyProperty]] ()
305-
var equivalentClassesMap = Map[OntologyProperty,Set[OntologyProperty]] ()
323+
var equivalentPropertiesBuilderMap = Map[OntologyProperty,Set[PropertyBuilder]] () //[wikidataprop,Set[DBpediaeq props]]
324+
var equivalentClassesMap = Map[OntologyProperty,Set[OntologyProperty]] () //[wikidataclass,Set[DBpediaeq class]]
306325

307326
def build() : Ontology =
308327
{
309328
val classMap = classes.map( clazz => (clazz.name, clazz) ).toMap
310329
val propertyMap = properties.map( property => (property.name, property) ).toMap
311330
val typeMap = datatypes.map( datatype => (datatype.name, datatype) ).toMap
312331

332+
// //change propertyBuilder to ontologyproperty class
333+
// var equivalentOntologyPropertiesMap = Map[OntologyProperty,Set[OntologyProperty]]()
334+
//
335+
// equivalentPropertiesBuilderMap.foreach({m=>
336+
// equivalentOntologyPropertiesMap += m._1 -> m._2.flatMap(_.build(classMap, typeMap))
337+
// })
338+
339+
//filling ontology class with properties , classes , sameas properties , sameas classes
313340
new Ontology( classes.flatMap(_.build(classMap)).map(c => (c.name, c)).toMap,
314341
properties.flatMap(_.build(classMap, typeMap)).map(p => (p.name, p)).toMap,
315342
datatypes.map(t => (t.name, t)).toMap,
316343
specializedProperties.flatMap(_.build(classMap, propertyMap, typeMap)).toMap,
317-
equivalentPropertiesMap,
344+
equivalentPropertiesBuilderMap.map{m=>m._1 -> m._2.flatMap(_.build(classMap, typeMap))},
318345
equivalentClassesMap)
319346
}
320347
}

0 commit comments

Comments
 (0)