@@ -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