Exemplo n.º 1
0
    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 = []

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        results = ql.process_query(sqg.get_start_point().query)

        for result in results:
            g  = result["g"]
            uri = result["nodeUri"]
            label = result["nodeLabel"]

            if 'private' in result['accesLevel']:
                public = False
                private = True
            else:
                public = True
                private = False

            nodes.append({'g': g, 'uri': uri, 'label': label, 'public': public, 'private': private})

        return nodes
Exemplo n.º 2
0
    def test_triple_presence(self, graph, triple):
        """Test the presence of a triple in the triplestore

        get if a triple is present in a specific graph of the triplestore
        :param graph: the named graph
        :type graph: string
        :param triple: the triple to test
        :type triple: string
        :returns: Result of the test
        :rtype: bool
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        query = sqb.prepare_query("""
            SELECT count(*) AS ?count
            WHERE {
                GRAPH <""" + graph + """> {
                    """ + triple + """ .
                }
            }
            """)

        res = query_laucher.process_query(query)

        print(bool(int(res[0]['count'])))

        return bool(int(res[0]['count']))
Exemplo n.º 3
0
    def delete_askograph(self):
        """Delete the askomics graph"""

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        query_laucher.process_query(sqb.get_drop_named_graph('urn:sparql:test_askomics').query)
Exemplo n.º 4
0
    def test_triple_presence(self, graph, triple):
        """Test the presence of a triple in the triplestore

        get if a triple is present in a specific graph of the triplestore
        :param graph: the named graph
        :type graph: string
        :param triple: the triple to test
        :type triple: string
        :returns: Result of the test
        :rtype: bool
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)


        query = sqb.prepare_query("""
            SELECT count(*) AS ?count
            WHERE {
                GRAPH <""" + graph + """> {
                    """ + triple + """ .
                }
            }
            """)

        res = query_laucher.process_query(query)

        print(bool(int(res[0]['count'])))

        return bool(int(res[0]['count']))
Exemplo n.º 5
0
    def delete_askograph(self):
        """Delete the askomics graph"""

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        query_laucher.process_query(sqb.get_drop_named_graph('urn:sparql:test_askomics'))
Exemplo n.º 6
0
    def delete_users(self):
        """Delete the test users graph"""

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        query_laucher.execute_query(
            sqb.get_drop_named_graph('urn:sparql:test_askomics:users').query)
Exemplo n.º 7
0
    def getUserAbstraction(self, service):
        """
        Get the user abstraction (relation and entity as subject and object)

        :return:
        :rtype:
        """
        data = {}
        self.log.debug(
            " =========== TripleStoreExplorer:getUserAbstraction ===========")

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        data['relations'] = ql.process_query(
            sqg.get_abstraction_relation('owl:ObjectProperty').query)
        data['subclassof'] = ql.process_query(
            sqg.get_isa_relation_entities().query)
        data['entities'] = ql.process_query(sqg.get_abstraction_entity().query)
        data['attributes'] = ql.process_query(
            sqg.get_abstraction_attribute_entity().query)
        data['categories'] = ql.process_query(
            sqg.get_abstraction_category_entity().query)
        data['positionable'] = ql.process_query(
            sqg.get_abstraction_positionable_entity().query)
        data['graph'] = sqg.getGraphUser()

        return data
Exemplo n.º 8
0
    def empty(self):
        """Delete all test data

        Get the list of all public and private graphs and delete them
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)
        private_graphs = self.list_private_graphs()
        public_graphs = self.list_public_graphs()

        for graph in private_graphs:
            query_laucher.process_query(sqb.get_delete_query_string(graph))

        for graph in public_graphs:
            query_laucher.process_query(sqb.get_delete_query_string(graph))
Exemplo n.º 9
0
    def empty(self):
        """Delete all test data

        Get the list of all public and private graphs and delete them
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)
        private_graphs = self.list_private_graphs()
        public_graphs = self.list_public_graphs()

        for graph in private_graphs:
            query_laucher.process_query(sqb.get_delete_query_string(graph))

        for graph in public_graphs:
            query_laucher.process_query(sqb.get_delete_query_string(graph))
Exemplo n.º 10
0
    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
        """
        #FIXME: Useless function, always return an empty list
        self.log.debug("existing_relations")
        existing_relations = []

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        results = ql.process_query(sqg.get_class_info_from_abstraction(self.headers[0]).query)

        return existing_relations
Exemplo n.º 11
0
    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
        """
        #FIXME: Useless function, always return an empty list
        self.log.debug("existing_relations")
        existing_relations = []

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        results = ql.process_query(
            sqg.get_class_info_from_abstraction(self.headers[0]).query)

        return existing_relations
Exemplo n.º 12
0
    def list_private_graphs(self):
        """List the private graphs

        :returns: decription of the private graphs
        :rtype: dict
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        res = query_laucher.process_query(sqb.get_user_graph_infos_with_count().query)

        named_graphs = []

        for index_result in range(len(res)):
            named_graphs.append(res[index_result]['g'])

        return named_graphs
Exemplo n.º 13
0
    def list_public_graphs(self):
        """list the public graphs

        :returns: description of the public graph
        :rtype: dict
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        res = query_laucher.process_query(sqb.get_public_graphs())

        named_graphs = []
        print(res)
        for index_result in range(len(res)):
            named_graphs.append(res[index_result]['g'])

        return named_graphs
Exemplo n.º 14
0
    def list_public_graphs(self):
        """list the public graphs

        :returns: description of the public graph
        :rtype: dict
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        res = query_laucher.process_query(sqb.get_public_graphs())

        named_graphs = []
        print(res)
        for index_result in range(len(res)):
            named_graphs.append(res[index_result]['g'])

        return named_graphs
Exemplo n.º 15
0
    def list_private_graphs(self):
        """List the private graphs

        :returns: decription of the private graphs
        :rtype: dict
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        res = query_laucher.process_query(sqb.get_user_graph_infos_with_count())

        named_graphs = []

        for index_result in range(len(res)):
            named_graphs.append(res[index_result]['g'])

        return named_graphs
Exemplo n.º 16
0
    def list_public_graphs(self):
        """list the public graphs

        :returns: description of the public graph
        :rtype: dict
        """

        sqb = SparqlQueryGraph(self.settings, self.request.session)
        query_laucher = QueryLauncher(self.settings, self.request.session)

        res = query_laucher.execute_query(sqb.get_public_graphs().query)

        named_graphs = []

        for index_result in range(len(res['results']['bindings'])):
            named_graphs.append(
                res['results']['bindings'][index_result]['g']['value'])

        return named_graphs
Exemplo n.º 17
0
    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 = []

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = MultipleQueryLauncher(self.settings, self.session)
        em = EndpointManager(self.settings, self.session)

        lEndp = em.listActiveEndpoints()
        results = ql.process_query(sqg.get_public_start_point().query,lEndp,indexByEndpoint=True)
        r2 = ql.process_query(sqg.get_user_start_point().query,lEndp,indexByEndpoint=True)

        for key, value in r2.items():
            if key in results:
                for elt in value:
                    results[key].append(elt)
            else:
                results[key] = r2[key]

        for endpoint in results:
            for result in results[endpoint]:
                g  = result["g"]
                uri = result["nodeUri"]
                label = result["nodeLabel"]

                if ('accesLevel' in result) and ('private' in result['accesLevel']):
                    public = False
                    private = True
                else:
                    public = True
                    private = False

                nodes.append({'endpoint' : endpoint,'g': g, 'uri': uri, 'label': label, 'public': public, 'private': private})
        return nodes
Exemplo n.º 18
0
    def get_prefix_uri(self):
        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        rs = ql.process_query(sqg.get_prefix_uri().query)
        results = {}
        r_buf = {}

        for r in rs:
            label = r['nodeLabel']
            prefix = r['prefUri']

            if label not in results:
                results[label] = []
                r_buf[label] = {}
                results[label].append(self.get_param("askomics.prefix"))
                r_buf[label][self.get_param("askomics.prefix")]=0

            if prefix not in r_buf[label]:
                results[label].append(prefix);
                r_buf [label][prefix]=0;

        return results
Exemplo n.º 19
0
    def get_prefix_uri(self):
        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        rs = ql.process_query(sqg.get_prefix_uri().query)
        results = {}
        r_buf = {}

        for r in rs:
            label = r['nodeLabel']
            prefix = r['prefUri']

            if label not in results:
                results[label] = []
                r_buf[label] = {}
                results[label].append(self.get_param("askomics.prefix"))
                r_buf[label][self.get_param("askomics.prefix")] = 0

            if prefix not in r_buf[label]:
                results[label].append(prefix)
                r_buf[label][prefix] = 0

        return results
Exemplo n.º 20
0
    def get_prefix_uri(self):
        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = MultipleQueryLauncher(self.settings, self.session)
        em = EndpointManager(self.settings, self.session)
        rs = ql.process_query(sqg.get_prefix_uri().query,em.listActiveEndpoints())
        results = {}
        r_buf = {}

        for r in rs:
            label = r['nodeLabel']
            prefix = r['prefUri']

            if label not in results:
                results[label] = []
                r_buf[label] = {}
                results[label].append(self.get_param("askomics.prefix"))
                r_buf[label][self.get_param("askomics.prefix")]=0

            if prefix not in r_buf[label]:
                results[label].append(prefix);
                r_buf [label][prefix]=0;

        return results
Exemplo n.º 21
0
    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 = []

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        results = ql.process_query(sqg.get_start_point().query)

        for result in results:
            g = result["g"]
            uri = result["nodeUri"]
            label = result["nodeLabel"]

            if 'private' in result['accesLevel']:
                public = False
                private = True
            else:
                public = True
                private = False

            nodes.append({
                'g': g,
                'uri': uri,
                'label': label,
                'public': public,
                'private': private
            })

        return nodes
Exemplo n.º 22
0
    def getUserAbstraction(self,service):
        """
        Get the user abstraction (relation and entity as subject and object)

        :return:
        :rtype:
        """
        data = {}
        self.log.debug(" =========== TripleStoreExplorer:getUserAbstraction ===========")

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)

        data['relations'] = ql.process_query(sqg.get_abstraction_relation('owl:ObjectProperty').query)
        data['subclassof'] = ql.process_query(sqg.get_isa_relation_entities().query)
        data['entities'] = ql.process_query(sqg.get_abstraction_entity().query)
        data['attributes'] = ql.process_query(sqg.get_abstraction_attribute_entity().query)
        data['categories'] = ql.process_query(sqg.get_abstraction_category_entity().query)
        data['positionable'] = ql.process_query(sqg.get_abstraction_positionable_entity().query)
        data['graph'] = sqg.getGraphUser()

        return data
Exemplo n.º 23
0
    def getUserAbstraction(self):
        """
        Get the user abstraction (relation and entity as subject and object)

        :return:
        :rtype:
        """
        data = {}
        self.log.debug(" =========== TripleStoreExplorer:getUserAbstraction ===========")

        sqg = SparqlQueryGraph(self.settings, self.session)
        ql = MultipleQueryLauncher(self.settings, self.session)
        em = EndpointManager(self.settings, self.session)
        lEndp = em.listActiveEndpoints()

        data['relations'] = ql.process_query(sqg.get_public_abstraction_relation('owl:ObjectProperty').query,lEndp)
        data['relations'] += ql.process_query(sqg.get_user_abstraction_relation('owl:ObjectProperty').query,lEndp)
        data['subclassof'] = ql.process_query(sqg.get_isa_relation_entities().query,lEndp)
        data['entities'] = ql.process_query(sqg.get_public_abstraction_entity().query,lEndp)
        data['entities'] += ql.process_query(sqg.get_user_abstraction_entity().query,lEndp)
        data['attributes'] = ql.process_query(sqg.get_public_abstraction_attribute_entity().query,lEndp)
        data['attributes'] += ql.process_query(sqg.get_user_abstraction_attribute_entity().query,lEndp)
        data['categories'] = ql.process_query(sqg.get_public_abstraction_category_entity().query,lEndp)
        data['categories'] += ql.process_query(sqg.get_user_abstraction_category_entity().query,lEndp)
        data['positionable'] = ql.process_query(sqg.get_abstraction_positionable_entity().query,lEndp)
        data['endpoints'] = sqg.getGraphUser()
        data['endpoints_ext'] = sqg.getExternalServiceEndpoint()

        self.log.debug("============== ENDPOINTS AND GRAPH =====================================")
        self.log.debug(data['endpoints'])
        return data