当前位置: 首页>>代码示例>>Python>>正文


Python SparqlQueryBuilder.load_from_file方法代码示例

本文整理汇总了Python中askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder.load_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python SparqlQueryBuilder.load_from_file方法的具体用法?Python SparqlQueryBuilder.load_from_file怎么用?Python SparqlQueryBuilder.load_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder的用法示例。


在下文中一共展示了SparqlQueryBuilder.load_from_file方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compare_file_to_database

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def compare_file_to_database(self, headers):
        """ Ask the database to compare the headers of a file to convert to the corresponding class in the database """
        curr_entity = headers[0]
        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        sparql_template = self.get_template_sparql(self.ASKOMICS_get_class_info_from_abstraction_queryFile)
        query = sqb.load_from_file(sparql_template, {"#nodeClass#": curr_entity}).query

        results = ql.process_query(query)
        if results == []:
            return [], headers, []
        bdd_relations, new_headers, missing_headers, present_headers = [], [], [], []
        for result in results:
            bdd_relation = result["relation"].replace(self.get_param("askomics.prefix"), "").replace("has_", "")
            bdd_relations.append(bdd_relation)
            if bdd_relation not in headers:
                self.log.warning('Relation "%s" not found in tables columns: %s.', bdd_relation, repr(headers))
                missing_headers.append(bdd_relation)
        for header in headers:
            if header != curr_entity:
                if header not in bdd_relations:
                    self.log.info('Adding column "%s".', header)
                    new_headers.append(header)
                elif header not in missing_headers:
                    present_headers.append(header)
        return missing_headers, new_headers, present_headers
开发者ID:odameron,项目名称:askomics,代码行数:28,代码来源:SourceFileConvertor.py

示例2: get_attributes_of

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def get_attributes_of(self, uri):
        """
        Get all attributes of a node class (identified by his uri). These
        attributes are known thanks to the domain knowledge of your RDF database.

        :param uri: Uri of the node class
        :type uri: str
        :return: All attributes of a node class
        :rtype: Attribute list
        """
        self.log.debug(" =========== TripleStoreExplorer:get_attributes_of ===========")
        attributes = []
        results = []

        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        fragment = uri.rsplit('#', 1)[-1]
        parent = fragment + str(self.get_new_id(fragment))

        # Send a request to know all the neighbors of a node (from uri).
        sparql_template = self.get_template_sparql(self.ASKOMICS_neighbor_query_file)

        query = sqb.load_from_file(sparql_template, {
            "nodeClass": '<%s>' % uri,
            "neighborClass": "?nodeUri"
            }).query

        results = (ql.process_query(query))
        for result in results:
            neighbor_uri = result["relationUri"]
            if 'nodeLabel' in result:
                neighbor_label = result["nodeLabel"]
            else:
                neighbor_label = result["relationLabel"]

            neighbor_id = neighbor_label + str(self.get_new_id(neighbor_label))

            if self.has_setting(result["nodeUri"], 'attribute') or self.has_setting(neighbor_uri, 'attribute'):
                attributes.append(
                    Attribute(neighbor_id,
                        neighbor_uri,
                        result["nodeUri"],
                        neighbor_label,
                        parent)
                    )

        return attributes
开发者ID:Piezoid,项目名称:askomics,代码行数:50,代码来源:TripleStoreExplorer.py

示例3: existing_relations

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def existing_relations(self):
        """
        Fetch from triplestore the existing relations if entities of the same name exist

        :return: a List of relation names
        :rtype: List
        """
        self.log.debug("existing_relations")
        existing_relations = []

        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        sparql_template = self.get_template_sparql(self.ASKOMICS_get_class_info_from_abstraction_queryFile)
        query = sqb.load_from_file(sparql_template, {"nodeClass": self.headers[0]}).query

        results = ql.process_query(query)

        return existing_relations
开发者ID:cbettemb,项目名称:askomics,代码行数:21,代码来源:SourceFile.py

示例4: has_category

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def has_category(self, entity, category, uri_category):
        """
        Get different categories for a node class.

        :param entity : Name of the entity associated with the node
        :param uri: Name of the node
        :type uri: str
        :return: List of categories
        :rtype: list

        """
        self.log.debug(" =========== TripleStoreExplorer:has_category ===========[ entity:"+ entity + ", category:"+ category+"]")
        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        sparql_template = self.get_template_sparql(self.ASKOMICS_has_category_query_file)
        query = sqb.load_from_file(sparql_template, {"#nodeClass#": uri_category, "#category#" : category, "#entity#" : entity}).query
        results = ql.process_query(query)

        return [res["label"] for res in results]
开发者ID:odameron,项目名称:askomics,代码行数:21,代码来源:TripleStoreExplorer.py

示例5: has_setting

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def has_setting(self, uri, setting):
        """
        Look for a specific setting (see displaySetting in your domain knowledge) for a node class.

        :param uri: Name of the node
        :param setting: Name of your setting
        :type uri: str
        :type setting: str
        :return: List of results found for a setting
        :rtype: dict

        """
        self.log.debug(" =========== TripleStoreExplorer:has_setting =========== [ uri:"+ uri + ", setting:"+ setting+"]")
        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        sparql_template = self.get_template_sparql(self.ASKOMICS_setting_query_file)
        query = sqb.load_from_file(sparql_template, {"#nodeClass#": uri, "#setting#": setting}).query
        results = ql.process_query(query)

        return [res[setting] for res in results]
开发者ID:odameron,项目名称:askomics,代码行数:22,代码来源:TripleStoreExplorer.py

示例6: get_start_points

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def get_start_points(self):
        """
        Get the possible starting points for your graph.

        :return: List of starting points
        :rtype: Node list
        """
        self.log.debug(" =========== TripleStoreExplorer:get_start_points ===========")
        nodes = []

        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        sparql_template = self.get_template_sparql(self.ASKOMICS_initial_query)
        query = sqb.load_from_file(sparql_template, {}).query
        results = ql.process_query(query)

        for result in results:
            uri = result["nodeUri"]
            label = result["nodeLabel"]
            nodes.append({ 'uri': uri, 'label': label })

        return nodes
开发者ID:cbettemb,项目名称:askomics,代码行数:24,代码来源:TripleStoreExplorer.py

示例7: getUserAbstraction

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def getUserAbstraction(self):
        """
        Get the user abstraction (relation and entity as subject and object)

        :return:
        :rtype:
        """
        data = {}
        listEntities = {}

        self.log.debug(" =========== TripleStoreExplorer:getUserAbstraction ===========")

        nodes_startpoint = self.get_start_points()
        # add start node at first
        for node in nodes_startpoint:
            listEntities[node['uri']]=0

        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        sparql_template = self.get_template_sparql(self.ASKOMICS_abstractionRelationUser)
        query = sqb.load_from_file(sparql_template, { 'OwlProperty' : 'owl:ObjectProperty'}).query
        results = ql.process_query(query)

        data['relations'] = results

        for elt in results:
            if not elt['object'] in listEntities:
                listEntities[elt['object']]=0
            if not elt['subject'] in listEntities:
                listEntities[elt['subject']]=0

        #sparql_template = self.get_template_sparql(self.ASKOMICS_abstractionRelationUser)
        #query = sqb.load_from_file(sparql_template, { 'OwlProperty' : 'owl:SymmetricProperty'}).query
        #results = ql.process_query(query)

        #data['relationsSym'] = results

        #for elt in results:
        #    if not elt['object'] in listEntities:
        #        listEntities[elt['object']]=0
        #    if not elt['subject'] in listEntities:
        #        listEntities[elt['subject']]=0

        filterEntities = ' '.join(["<"+s+">" for s in listEntities.keys()])
        sparql_template = self.get_template_sparql(self.ASKOMICS_abstractionEntityUser)
        query = sqb.load_from_file(sparql_template, {"entities" : filterEntities }).query
        results = ql.process_query(query)

        data['entities'] = results

        sparql_template = self.get_template_sparql(self.ASKOMICS_abstractionAttributesEntityUser)
        query = sqb.load_from_file(sparql_template, {"entities" : filterEntities }).query
        results = ql.process_query(query)

        data['attributes'] = results

        sparql_template = self.get_template_sparql(self.ASKOMICS_abstractionCategoriesEntityUser)
        query = sqb.load_from_file(sparql_template, {"entities" : filterEntities }).query
        results = ql.process_query(query)

        data['categories'] = results

        sparql_template = self.get_template_sparql(self.ASKOMICS_abstractionPositionableEntityUser)
        query = sqb.load_from_file(sparql_template, {}).query
        results = ql.process_query(query)

        data['positionable'] = results


        return data
开发者ID:cbettemb,项目名称:askomics,代码行数:73,代码来源:TripleStoreExplorer.py

示例8: get_neighbours_for_node

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def get_neighbours_for_node(self, node, uri_new_instance):
        """
        Get all neighbors of a node in the RDF database. This function
        process the results from the database based on your domain knowledge
        (if there are attributes, hidden neighbor, neighbor with a relation
        which can be specified or normal neighbor).

        :param node: Source node
        :type node: Node
        :param uri_new_instance : uri of the new element asked ("None" value instanciate all elements)
        :return: A tuple (attribute, node, link) which contains in first position
                a list of all the attribute of our node class, follows by a list of all the nodes in
                relation with our source node and finnally a list which contains all the
                links to those nodes.
        :rtype: (Attribute list, Node list, Link list)

        """
        self.log.debug(" =========== TripleStoreExplorer:get_neighbours_for_node ===========")
        results = {'direct':[], 'reverse':[]}
        nodes = []
        links = []
        attributes = []
        shortcuts_list = []

        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        # Search for shortcuts if there is.
        if len(node.get_shortcuts()) > 0:
            sparql_template = self.get_template_sparql(self.ASKOMICS_neighbor_query_following_shortcuts_file)

            for shortcut in node.get_shortcuts():
                query = sqb.load_from_file(sparql_template, {"#nodeClass#": node.get_uri(), "#shortcut#": shortcut}).query
                results["direct"] = ql.process_query(query)

                for result in results["direct"]:
                    result["relationUri"] = shortcut
                    result["relationLabel"] = "has"

        # Send a request to know all the neighbors of a node (from and to node).
        sparql_template = self.get_template_sparql(self.ASKOMICS_neighbor_query_file)

        query = sqb.load_from_file(sparql_template, {
            "#nodeClass#": "<" + node.get_uri() + ">",
            "#neighborClass#": "?nodeUri"
            }).query

        reverse_query = sqb.load_from_file(sparql_template, {
            "#nodeClass#": "?nodeUri",
            "#neighborClass#": "<" + node.get_uri() + ">"
            }).query

        results["direct"].extend(ql.process_query(query))
        results["reverse"] = ql.process_query(reverse_query)

        # remove identity relation (exemple Personne has_Personne) in the reverse otherwise there two proposition on the graph
        for r1 in results["direct"]:
            for r2 in results["reverse"]:
                if r1['nodeUri'] == r2['nodeUri'] and r1['relationUri'] == r2['relationUri']:
                    results["reverse"].remove(r2)

        self.print_stat()

        go_out_loop = False
        # Sort the results between attributes, nodes and links
        for direction in results:
            for result in results[direction]:
                neighbor_uri = result["nodeUri"]
                self.log.debug("URI===>"+neighbor_uri)

                # We just want to add a new possibility of instance for a previous node
                if uri_new_instance != None:
                    if uri_new_instance == neighbor_uri:
                        go_out_loop = True
                    else:
                        continue

                neighbor_label = result["nodeLabel"] if 'nodeLabel' in result else result["relationLabel"]

                if  not self.ASKOMICS_prefix["xsd"] in neighbor_uri:
                    if self.has_setting(neighbor_uri, 'hidden'):
                        continue

                shortcuts_list = self.has_setting(neighbor_uri, 'shortcut')

                spec = self.has_setting(result["relationUri"], 'specified_by')
                specified_by = spec[0] if spec else ""

                clause = self.has_setting(result["relationUri"], 'specialQuery')
                spec_clause = clause[0] if clause else ""
                #if uri_new_instance == None or uri_new_instance == neighbor_uri:
                att_h = self.has_setting(result["nodeUri"], 'attribute')
                rel_h = self.has_setting(result["relationUri"], 'attribute')

                if att_h or rel_h or (result["propertyType"] == self.ASKOMICS_prefix["owl"] + "DatatypeProperty"):
                    self.log.debug("====>ATTRIB")
                    attribute_id = node.get_id() + '_' + neighbor_label + str(self.get_new_id(node.get_id() + '_' + neighbor_label))
                    attributes.append(
                        Attribute(attribute_id,
                            result["relationUri"],
#.........这里部分代码省略.........
开发者ID:odameron,项目名称:askomics,代码行数:103,代码来源:TripleStoreExplorer.py

示例9: test_load_from_file

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import load_from_file [as 别名]
    def test_load_from_file(self):
        request = testing.DummyRequest()
        sqb = SparqlQueryBuilder(self.settings, request.session)
        temp = self.get_template1()

        sqb.load_from_file(temp)
开发者ID:cbettemb,项目名称:askomics,代码行数:8,代码来源:sparql_test.py


注:本文中的askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder.load_from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。