def rate(resource, rating): '''give a resource a nao:numericRating (float from 1-10)''' resource = RDF.Node(RDF.Uri(resource)) rating = RDF.Node(literal=str(rating), datatype=ns['xs'].float.uri) # delete any existing ratings for this resource TripleStore.forget(resource, ns['nao'].numericRating, None) TripleStore.state(resource, ns['nao'].numericRating, rating)
def tag(resource, tags): '''tag a resource with a space-separated string''' resource = RDF.Node(RDF.Uri(resource)) # space-separated, remove empty tags = [x for x in tags.strip().split(' ') if x != ''] # remove all existing tags on this resource TripleStore.forget(resource, ns['nao'].hasTag, None) for _tag in tags: # XXX check if it's a nao:Tag too tag = TripleStore.model.get_source(ns['nao'].prefLabel, RDF.Node(_tag)) if not tag: # create a new nao:Tag with the appropriate prefLabel tag = RDF.Node(blank=None) TripleStore.state(tag, ns['rdf'].type, ns['nao'].Tag) TripleStore.state(tag, ns['nao'].prefLabel, RDF.Node(_tag)) TripleStore.state(resource, ns['nao'].hasTag, tag)