Exemple #1
0
    def clusterForward(self, selection):
        """
        Forward clustering, using all the results of the query as
        seeds (when appropriate). It is based on the usage of the
        L{cluster forward<rdflib.sparql.sparqlGraph.clusterForward>}
        method for triple store.

        @param selection: a selection to define the seeds for
        clustering via the selection; the result of select used for
        the clustering seed

        @return: a new triple store
        @rtype: L{sparqlGraph<rdflib.sparql.sparqlGraph>}
        """
        if self.parent1 != None and self.parent2 != None:
            return self.parent1.clusterForward(
                selection) + self.parent2.clusterForward(selection)
        else:
            clusterF = SPARQLGraph()
            for r in reduce(lambda x, y: list(x) + list(y),
                            self.select(selection), ()):
                try:
                    check_subject(r)
                    self.triples.clusterForward(r, clusterF)
                except:
                    # no real problem, this is a literal, just forget about it
                    continue
            return clusterF
Exemple #2
0
    def clusterForward(self,selection) :
        """
        Forward clustering, using all the results of the query as
        seeds (when appropriate). It is based on the usage of the
        L{cluster forward<rdflib.sparql.sparqlGraph.clusterForward>}
        method for triple store.

        @param selection: a selection to define the seeds for
        clustering via the selection; the result of select used for
        the clustering seed

        @return: a new triple store
        @rtype: L{sparqlGraph<rdflib.sparql.sparqlGraph>}
        """
        if self.parent1 != None and self.parent2 != None :
            return self.parent1.clusterForward(selection) + self.parent2.clusterForward(selection)
        else :
            clusterF = SPARQLGraph()
            for r in reduce(lambda x,y: list(x) + list(y),self.select(selection),()) :
                try :
                    check_subject(r)
                    self.triples.clusterForward(r,clusterF)
                except :
                    # no real problem, this is a literal, just forget about it
                    continue
            return clusterF
Exemple #3
0
    def clusterForward(self, seed, Cluster=None):
        """
        Cluster the triple store: from a seed, transitively get all
        properties and objects in direction of the arcs.

        :param seed: RDFLib Resource

        :param Cluster: another :class:`~rdfextras.sparql2sql.sql.sparqlGraph` instance; if None, a new
        one will be created. The subgraph will be added to this graph.

        :returns: The triple store containing the cluster

        :rtype: :class:`~rdfextras.sparql2sql.sql.sparqlGraph`
        """
        if Cluster == None:
            Cluster = SPARQLGraph()

        # This will raise an exception if not kosher...
        check_subject(seed)  # print "Wrong type for clustering (probably a literal): %s" % seed
        self._clusterForward(seed, Cluster)
        return Cluster
Exemple #4
0
    def clusterForward(self, seed, Cluster=None):
        """
        Cluster the triple store: from a seed, transitively get all
        properties and objects in direction of the arcs.

        :param seed: RDFLib Resource

        :param Cluster: another sparqlGraph instance; if None, a new
            one will be created. The subgraph will be added to this graph.

        :return:  The :class:`~rdfextras.sparql.graph.SPARQLGraph` triple store
            containing the cluster

        """
        if Cluster == None:
            Cluster = SPARQLGraph()

        # This will raise an exception if not kosher...
        check_subject(seed) #print "Wrong type for clustering: %s" % seed
        self._clusterForward(seed, Cluster)

        return Cluster
Exemple #5
0
 def test_util_check_subject(self):
     res = util.check_subject(self.s)
     self.assertTrue(res == None)
Exemple #6
0
 def test_util_check_subject(self):
     res = util.check_subject(self.s)
     self.assert_(res == None)