def setup(self): # Create a namespace object for the Friend of a friend namespace. self.FOAF = Namespace("http://xmlns.com/foaf/0.1/") self.TRUST = Namespace("http://www.abundantplunder.com/trust/owl/trust.owl#") self.WOT = Namespace("http://xmlns.com/wot/0.1/") self.RDF = Namespace("http://www.w3.org/2000/01/rdf-schema#") # load trust values into list for later trust = TripleStore() trust.load("http://www.abundantplunder.com/trust/owl/trust.owl#") self.trustValues = [] for s in trust.subjects(self.RDF["subPropertyOf"], self.TRUST["trustValue"]): self.trustValues.append(s)
def load(self, source): # TODO: don't let duplicate trust levels on certain subjects be entered! print "Update Listener: parsing input" # this is the main object we're concerned with store = TripleStore() store.load(source) # For each foaf:Person in the store print out its mbox property. truster = store.subjects(self.TRUST["trusts"]).next() f = store.objects(truster, self.WOT["fingerprint"]).next() p = self.server.getPerson(f) for trustee in store.objects(truster, self.TRUST["trusts"]): f2 = store.objects(trustee, self.WOT["fingerprint"]).next() # we do this to make sure they exist. p2 = self.server.getPerson(f2) for value, resource in store.predicate_objects(trustee): if value in self.trustValues: p.addTrustLink(f2, resource.split("#")[1], resource, TrustValue.TrustValue(value.split("#")[1]))
def handle__t__test(self, testURI="http://www.w3.org/TR/owl-test/Manifest.rdf"): """Load a test description (manifest) and run the tests. Testing is done in a manner set by previous options. (such as...?) Reasonable options include all the various RDF and OWL tests, such as in http://www.w3.org/2002/03owlt/editors-draft/draft/Manifest.rdf """ store = TripleStore() print "Loading %s..." % testURI, store.load(testURI) print " Done." resultStore = TripleStore() try: runTests(store, resultStore) except KeyboardInterrupt, k: print "KeyboardInterrupt"
def load(self, source): print "Update Listener: parsing input: %s" % source # this is the main object we're concerned with store = TripleStore() store.load(source) # For each foaf:Person in the store print out its mbox property. truster = store.subjects(self.TRUST["trusts"]).next() f = store.objects(truster, self.WOT["fingerprint"]).next() p = self.server.getPerson(f) for trustee in store.objects(truster, self.TRUST["trusts"]): f2 = store.objects(trustee, self.WOT["fingerprint"]).next() # we do this to make sure they exist. p2 = self.server.getPerson(f2) for value, resource in store.predicate_objects(trustee): if value in self.trustValues: self.server.lock.acquire_write() #time.sleep(15) p.addTrustLink(f2, resource.split("#")[1], resource, BasicTrustValue(value.split("#")[1])) self.server.lock.release_write()
def setup(self): # Create a namespace object for the Friend of a friend namespace. # figure out trailing pound thing... #self.FOAF = Namespace(self.server.config.foaf_url + "#") #self.TRUST = Namespace(self.server.config.trust_url + "#") #self.WOT = Namespace(self.server.config.wot_url + "#") #self.RDF = Namespace(self.server.config.rdf_url + "#") self.FOAF = Namespace("http://xmlns.com/foaf/0.1/#") self.TRUST = Namespace("http://brondsema.gotdns.com/svn/dmail/schema/tags/release-1.0/trust.owl#") self.WOT = Namespace("http://xmlns.com/wot/0.1/#") self.RDF = Namespace("http://www.w3.org/2000/01/rdf-schema#") # load trust values into list for later trust = TripleStore() #trust.load(self.server.config.trust_url) trust.load("http://brondsema.gotdns.com/svn/dmail/schema/tags/release-1.0/trust.owl#") self.trustValues = [] for s in trust.subjects(self.RDF["subPropertyOf"], self.TRUST["trustValue"]): self.trustValues.append(s)
def load(self, source): print "Update Listener: parsing input: %s" % source # this is the main object we're concerned with trust = TripleStore() trust.load(source) # new version count = 0 for (relationship, truster) in trust.subject_objects(self.TRUST["truster"]): # clean up the fingerprints source_fingerprint = trust.objects(truster, self.WOT["fingerprint"]).next() sink_fingerprint = trust.objects(trust.objects(relationship, self.TRUST["trusted"]).next(), self.WOT["fingerprint"]).next() # turn these off for now, for our test cases. figure a better solution later source_fingerprint = re.sub(r'[^0-9A-Z]', r'', source_fingerprint.upper()) sink_fingerprint = re.sub(r'[^0-9A-Z]', r'', sink_fingerprint.upper()) source = self.server.getPerson(source_fingerprint) sink = self.server.getPerson(sink_fingerprint) for item in trust.objects(relationship, self.TRUST["about"]): topic = trust.objects(item, self.TRUST["topic"]).next().split("#")[1] rating = float(trust.objects(item, self.TRUST["rating"]).next()) if rating >= 0.0 and rating <= 1.0: source.addTrustLink(sink.getFingerprint(), topic, rating) count += 1 return "Added %d trust links." % count
def extractXMPTriples(fname, triples=None): """Extract the XMP RDF data for PDF and JPG files and return and RDFLib triple store. If the triples parameter is not None, then it is considered to be an already existing triple store that has to be extended by the new set of triples. @param fname: the filename for the image or the pdf file @type fname: a string, denoting the file name @param triples: an RDFLib TripleStore (default: None) @type triples: rdflib.TripleStore @return: triples @rtype: RDFLib TripleStore """ rdf = extractXMP(fname) # If it is at that point, no exception has been raised, ie, the rdf content exists # # Note the import here, not in the header; the module should be usable without RDFLib, too... from rdflib.TripleStore import TripleStore if triples == None: triples = TripleStore() # The logical thing to do would be to wrap rdf into a StringIO and load it into the triples # but that does not work with TripleStore, which expects a file name (or I have not found other means) # Ie, the rdf content should be stored in a temporary file. tempfile = fname + "__.rdf" store = file(tempfile, "w") store.write(rdf) store.flush() store.close() triples.load(tempfile) try: # on Windows this may not work... os.remove(tempfile) except: # This works only when called from cygwin. However, is there anybody in his/her able mind # using Windows and python without some sort of a unix emulation ;-) os.system("rm %s" % tempfile) return triples
""" read XMP xml files """ # see http://www.xml.com/lpt/a/1107 # see also raptor-utls # rapper -o ntriples http://planetrdf.com/guide/rss.rdf # rapper -o ntriples ../tests/fixture/xmp/sample_xmp.rdf from rdflib.TripleStore import TripleStore from rdflib.Namespace import Namespace ns_dc = Namespace("http://purl.org/dc/elements/1.1/") ns_pr = Namespace("http://prismstandard.org/1.0#") store = TripleStore() store.load("../tests/fixture/xmp/sample_xmp.rdf") # print dir(store) quit() # For all triples that have prism:publicationTime as their predicate, for s, o in store.subject_objects(ns_pr["publicationTime"]): # if the triples' object is greater than the cutoff date, if o > cutOffDate: # print the date, author name, and title. print o, for object in store.objects(s, ns_dc["creator"]): print object + ": ", for object in store.objects(s, ns_dc["title"]): print object
def get_model(): model = TripleStore() model.load("file:/home/httpd/htdocs/foaf.rdf") return model
from rdflib.URIRef import URIRef from rdflib.Literal import Literal from rdflib.BNode import BNode from rdflib.Namespace import Namespace from rdflib.constants import TYPE from rdflib.TripleStore import TripleStore t = TripleStore() t.load("example.rdf", format="xml") print t
from rdflib.constants import DATATYPE import Person import TrustConnection import TrustSubject import TrustValue # Create a namespace object for the Friend of a friend namespace. FOAF = Namespace("http://xmlns.com/foaf/0.1/") TRUST = Namespace("http://www.abundantplunder.com/trust/owl/trust.owl#") WOT = Namespace("http://xmlns.com/wot/0.1/") RDF = Namespace("http://www.w3.org/2000/01/rdf-schema#") # this is the main object we're concerned with store = TripleStore() store.load("example2.rdf") # master dictionary containing all the people # will a plain old dictionary suffice, or do I need a hashtable? people = {} # load trust values into list for later trust = TripleStore() trust.load("http://www.abundantplunder.com/trust/owl/trust.owl#") trustValues = [] for s in trust.subjects(RDF["subPropertyOf"], TRUST["trustValue"]): trustValues.append(s) # For each foaf:Person in the store print out its mbox property. print "--- printing trust: ---" truster = store.subjects(TRUST["trusts"]).next()