Skip to content Skip to sidebar Skip to footer

Representing A Couple Of Rdf-triples Using Tensor. How To Programming This Modeling Process Using Python?

A question about representing a couple of RDF-triples using tensor. Scenario: A RDF-triple is used to express simple statements about resources, formatting (subject, predicate, obj

Solution 1:

There is a magnitude of possibilities to solve your problem, but there is a even bigger magnitutde of ambivalence in your question. Formulate it more precise, show what you want to get and why and show what you have tried so far.

It would have been better to explain why you need a n-th grade Tensor and why another representation wouldnt fit your needs, instead of explaining what rdf is.

Using a tensor just makes sense if you need tensor-operations. If so, you should look into numpy if not, you should think about an other solution. dictionaries may not be what you are looking for if you want to preserve the order in which you created the object. Maybe the OrderedDict from collections (python >= 2.7) is what you are looking for. But maybe namedtuple from collections would do it as well.

Solution 2:

pythons best library tool for rdf is rdflib An rdflib graph has a method of

lst = myGraph.subject_objects(MyNS.race_for)
# which is just syntactic sugar for:lst = myGraph.triples((None,MyNS.race_for,None))

The second syntax you also find in other libraries in other languages like Java-jena etc

Within scipy you should call sparse and use that for your sparse binary array.

Look at the numpy packages for your best way to "factorize" the subjects and objects returns from the triples query. should be pretty simple. There are libraries for this in pandas but my guess is that you will have large sparse matrices and you are better off with the scipy.sparse module.

Post a Comment for "Representing A Couple Of Rdf-triples Using Tensor. How To Programming This Modeling Process Using Python?"