def linked_data_discovery_for_alignment(self, entity_dbpedia_URI,
                                            entityClasses_labels):
        '''
        discovery DUL classes alignment suggestions by entity and entity class dereferencing URIs from DBpedia
        param:
        entity_dbpedia_URI : string, DBpedia URI string
        entity class labels: list, list of strings
        
        return a tuple containing suggested dul classes for alignment and all_possible_rdf_types
        '''
        from oke.oak.DBpediaQuerier import DBpediaQuerier
        import urllib

        dbpediaQuerier = DBpediaQuerier()
        try:
            entity_rdf_types = dbpediaQuerier.dbpedia_query_rdftypes(
                entity_dbpedia_URI)
        except urllib.error.URLError:
            print("===urllib.error.URLError")
        class_inst_rdftypes = self.type_alignment_by_dereferencing_types(
            entityClasses_labels)

        all_possible_rdf_types = set()
        all_possible_rdf_types.update(entity_rdf_types)
        all_possible_rdf_types.update(class_inst_rdftypes)

        dulClasses = [
            rdftype for rdftype in all_possible_rdf_types
            if self.is_dul_class(rdftype)
        ]

        #ontology mapping
        #dulClasses = self.wikipedia_d0_ontology_mapping(dulClasses)
        return (dulClasses, all_possible_rdf_types)
 def linked_data_discovery_for_alignment(self, entity_dbpedia_URI, entityClasses_labels):    
     '''
     discovery DUL classes alignment suggestions by entity and entity class dereferencing URIs from DBpedia
     param:
     entity_dbpedia_URI : string, DBpedia URI string
     entity class labels: list, list of strings
     
     return a tuple containing suggested dul classes for alignment and all_possible_rdf_types
     '''
     from oke.oak.DBpediaQuerier import DBpediaQuerier
     import urllib
     
     dbpediaQuerier = DBpediaQuerier()
     try:
         entity_rdf_types = dbpediaQuerier.dbpedia_query_rdftypes(entity_dbpedia_URI)
     except urllib.error.URLError:
         print("===urllib.error.URLError")
     class_inst_rdftypes = self.type_alignment_by_dereferencing_types(entityClasses_labels)
     
     all_possible_rdf_types=set()
     all_possible_rdf_types.update(entity_rdf_types)
     all_possible_rdf_types.update(class_inst_rdftypes)
     
     dulClasses=[rdftype for rdftype in all_possible_rdf_types if self.is_dul_class(rdftype)]
     
     #ontology mapping
     #dulClasses = self.wikipedia_d0_ontology_mapping(dulClasses)
     return (dulClasses,all_possible_rdf_types)
    def type_alignment_by_dereferencing_type(self,
                                             entity_class_dereferencing_uri=""
                                             ):
        '''
        Linked Data Discovery for alignment by dereferencing type URI
        
        params: a list of raw entity class expression in context
        
        Query DUL classes by autogenerated deferencing URIs of entity class expressions
        
        return a list of dbpedia type URI
        
        For example:
                  select distinct ?type where { {?instance dbpedia-owl:type <http://dbpedia.org/resource/Holding_company> .
                      ?instance a ?type .            
                  }
                  UNION
                  {
                    <http://dbpedia.org/resource/Holding_company> dbpedia-owl:wikiPageRedirects ?entity .
                    ?instance dbpedia-owl:type ?entity .
                    ?instance a ?type .
                  }
                  UNION
                  {
                    <http://dbpedia.org/resource/Holding_company> a ?type .
                  }
                  FILTER(?type != owl:Thing)
            }
        Example output:{'http://dbpedia.org/class/yago/Organization108008335',
                        'http://dbpedia.org/class/yago/Company108058098', 
                        'http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#SocialPerson',
                        'http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#Agent', 
                        'http://dbpedia.org/ontology/Company', ...}
        '''
        from oke.oak.DBpediaQuerier import DBpediaQuerier
        dbpediaQuerier = DBpediaQuerier()

        query = "select distinct ?type where { "
        query += " {?instance dbpedia-owl:type <%s> ." % entity_class_dereferencing_uri
        query += "  ?instance a ?type ."
        query += " } "
        query += " UNION "
        query += " { <%s> dbpedia-owl:wikiPageRedirects ?entity .?instance dbpedia-owl:type ?entity ." % entity_class_dereferencing_uri
        query += "   ?instance dbpedia-owl:type ?entity ."
        query += "   ?instance a ?type . }"
        query += " UNION "
        query += " { <%s> a ?type. }" % entity_class_dereferencing_uri
        query += " FILTER(?type != owl:Thing) "
        query += " } "
        results = dbpediaQuerier.dbpedia_query(query)

        alignment_suggestions = set()

        for results in results["results"]["bindings"]:
            alignment_suggestions.add(results['type']['value'])
        return alignment_suggestions
 def type_alignment_by_dereferencing_type(self, entity_class_dereferencing_uri=""):
     '''
     Linked Data Discovery for alignment by dereferencing type URI
     
     params: a list of raw entity class expression in context
     
     Query DUL classes by autogenerated deferencing URIs of entity class expressions
     
     return a list of dbpedia type URI
     
     For example:
               select distinct ?type where { {?instance dbpedia-owl:type <http://dbpedia.org/resource/Holding_company> .
                   ?instance a ?type .            
               }
               UNION
               {
                 <http://dbpedia.org/resource/Holding_company> dbpedia-owl:wikiPageRedirects ?entity .
                 ?instance dbpedia-owl:type ?entity .
                 ?instance a ?type .
               }
               UNION
               {
                 <http://dbpedia.org/resource/Holding_company> a ?type .
               }
               FILTER(?type != owl:Thing)
         }
     Example output:{'http://dbpedia.org/class/yago/Organization108008335',
                     'http://dbpedia.org/class/yago/Company108058098', 
                     'http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#SocialPerson',
                     'http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#Agent', 
                     'http://dbpedia.org/ontology/Company', ...}
     '''
     from oke.oak.DBpediaQuerier import DBpediaQuerier
     dbpediaQuerier=DBpediaQuerier()
     
     query="select distinct ?type where { "
     query+=" {?instance dbpedia-owl:type <%s> ." %entity_class_dereferencing_uri
     query+="  ?instance a ?type ."
     query+=" } "
     query+=" UNION "
     query+=" { <%s> dbpedia-owl:wikiPageRedirects ?entity .?instance dbpedia-owl:type ?entity ." %entity_class_dereferencing_uri
     query+="   ?instance dbpedia-owl:type ?entity ."
     query+="   ?instance a ?type . }"
     query+=" UNION "
     query+=" { <%s> a ?type. }" %entity_class_dereferencing_uri
     query+=" FILTER(?type != owl:Thing) "
     query+=" } "
     results = dbpediaQuerier.dbpedia_query(query)
     
     alignment_suggestions=set()
     
     for results in results["results"]["bindings"]:
         alignment_suggestions.add(results['type']['value'])
     return alignment_suggestions
 def entity_rdftypes_feature_extraction(self, entity_dbpedia_URI):
     '''
     Extracting entity RDF type as feature from DBpedia
     
     return set : entity rdf type set
     '''
     import SPARQLWrapper
     from oke.oak.DBpediaQuerier import DBpediaQuerier
     dbpediaQuerier = DBpediaQuerier()
     try:
         entity_rdftypes = dbpediaQuerier.dbpedia_query_rdftypes(entity_dbpedia_URI,endpoint="http://galaxy.dcs.shef.ac.uk:8893/sparql")
     except SPARQLWrapper.SPARQLExceptions.EndPointInternalError:
         print("EndPointInternalError: try default dbpedia endpoint next...")
     entity_rdftypes.update(dbpediaQuerier.dbpedia_query_rdftypes(entity_dbpedia_URI))
     #print("entity_rdftypes:",entity_rdftypes)
     return entity_rdftypes
Example #6
0
 def entity_rdftypes_feature_extraction(self, entity_dbpedia_URI):
     '''
     Extracting entity RDF type as feature from DBpedia
     
     return set : entity rdf type set
     '''
     import SPARQLWrapper
     from oke.oak.DBpediaQuerier import DBpediaQuerier
     dbpediaQuerier = DBpediaQuerier()
     try:
         entity_rdftypes = dbpediaQuerier.dbpedia_query_rdftypes(
             entity_dbpedia_URI,
             endpoint="http://galaxy.dcs.shef.ac.uk:8893/sparql")
     except SPARQLWrapper.SPARQLExceptions.EndPointInternalError:
         print(
             "EndPointInternalError: try default dbpedia endpoint next...")
     entity_rdftypes.update(
         dbpediaQuerier.dbpedia_query_rdftypes(entity_dbpedia_URI))
     #print("entity_rdftypes:",entity_rdftypes)
     return entity_rdftypes