Ejemplo n.º 1
0
	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)
Ejemplo n.º 2
0
class rdfStore:
    """
    Provides RDF parsing and output functions for CC license and work
    definitions.
    """
    
    def __init__(self):
        # initialize the TripleStore for managing RDF
        self.store = TripleStore()
        
    def parse(self, rdf):
        """
        Parse the given String, rdf, into it's component triples.
        """

        self.store.parse( StringInputSource (rdf) )

    def subjects(self):
        """A generator which successivly returns each subject contained in
        the store, wrapped in an instance of rdfDict."""

        for subject in self.store.subjects():
            yield rdfDict(subject, store=self.store)
        
    def output(self):
        """
        Return a string containing the RDF representation of the
        licenses and works."""

        if self.store is not None:
            rdf = cStringIO.StringIO()
            self.store.serialize(stream=rdf)
            return rdf.getvalue()
        else:
            return ""

    __str__ = output

    def append(self, newItem):
        """
        Adds a new work or license to the RDF store.
        """

        # make sure the stores aren't the same
        if (newItem.store is not self.store):

            # add each triple from the newItem's store to this store
            for triple in newItem.store.triples():
                self.store.add(triple)
Ejemplo n.º 3
0
	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]))
Ejemplo n.º 4
0
	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()
Ejemplo n.º 5
0
	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)
Ejemplo n.º 6
0
from rdflib.constants import DATATYPE

# Add triples using store's add method.
store.add((donna, TYPE, FOAF["Person"]))
store.add((donna, FOAF["nick"], Literal("donna")))
store.add((donna, FOAF["name"], Literal("Donna Fales")))

# Iterate over triples in store and print them out.
print "--- printing raw triples ---"
for s, p, o in store:
    print s, p, o
    
# For each foaf:Person in the store print out its mbox property.
print "--- printing mboxes ---"
for person in store.subjects(TYPE, FOAF["Person"]):
    for mbox in store.objects(person, FOAF["mbox"]):
        print mbox

# Serialize the store as RDF/XML to the file foaf.rdf.
store.save("foaf.rdf")

# Let's show off the serializers

print "RDF Serializations:"

# Serialize as XML
print "--- start: rdf-xml ---"
print store.serialize()
print "--- end: rdf-xml ---\n"
Ejemplo n.º 7
0
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()
f = store.objects(truster, WOT["fingerprint"]).next()
p = Person.Person(f)
people[f] = p

for trustee in store.objects(truster, TRUST["trusts"]):
	f2 = store.objects(trustee, WOT["fingerprint"]).next()
	p2 = Person.Person(f2)
	people[f2] = p2
	for value, subject in store.predicate_objects(trustee):
		if value in trustValues: