Exemplo n.º 1
0
Arquivo: surnia.py Projeto: weyls/swap
    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"
Exemplo n.º 2
0
        def __init__(self, source='', defaultStatements=(), context='', **kw):
            ntpath, stmts, format = _loadRDFFile(source, defaultStatements,
                                                 context)
            if format == 'unsupported':
                self.format = 'nt'
                self.path = ntpath
            else:
                self.format = (format == 'ntriples'
                               and 'nt') or (format == 'rdfxml'
                                             and 'xml') or 'error'
                assert self.format != 'error', 'unexpected format'
                self.path = source

            from rdflib.TripleStore import TripleStore
            RDFLibModel.__init__(self, TripleStore())
            for stmt in stmts:
                self.addStatement(stmt)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
    'http://www.w3.org/2001/XMLSchema#positiveInteger': (int, unicode),
    'http://www.w3.org/2001/XMLSchema#short': (int, unicode),
    'http://www.w3.org/2001/XMLSchema#unsignedInt': (long, unicode),
    'http://www.w3.org/2001/XMLSchema#byte': (int, unicode),
    'http://www.w3.org/2001/XMLSchema#unsignedShort': (int, unicode),
    'http://www.w3.org/2001/XMLSchema#unsignedByte': (int, unicode),
    'http://www.w3.org/2001/XMLSchema#float': (float, unicode),
    'http://www.w3.org/2001/XMLSchema#double': (float, unicode),  # doesn't do the whole range
    #    duration
    #    dateTime
    #    time
    #    date
    #    gYearMonth
    #    gYear
    #    gMonthDay
    #    gDay
    #    gMonth
    #    hexBinary
    'http://www.w3.org/2001/XMLSchema#base64Binary': (base64.decodestring, lambda i:base64.encodestring(i)[:-1]),
    'http://www.w3.org/2001/XMLSchema#anyURI': (str, str),
}

if __name__ == '__main__':
    # use: "python -i sparta.py [URI for RDF file]+"
    from rdflib.TripleStore import TripleStore
    import sys
    mystore = TripleStore()
    for arg in sys.argv[1:]:
        mystore.parse(arg)
    thing = ThingFactory(mystore)
Exemplo n.º 5
0
def get_model():
    model = TripleStore()
    model.load("file:/home/httpd/htdocs/foaf.rdf")
    return model
Exemplo n.º 6
0
                people[source][prop].append(i)
    if len(people) < 1:
        sources = model.subjects(FOAF['nick'], Literal(name_or_nick))
        for source in sources:
            people[source] = {}
            props = get_props()
            for prop in props.keys():
                people[source][prop] = list()
                available = model.objects(source, URIRef(props[prop][1]))
                for i in available:
                    people[source][prop].append(i)
    return people


if __name__ == "__main__":
    mem_model = TripleStore()
    wordlist = get_words()
    FOAF = Namespace("http://xmlns.com/foaf/0.1/")
    GEO = Namespace("http://www.w3.org/2003/01/geo/wgs84_pos#")
    RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
    DC = Namespace("http://purl.org/dc/elements/1.1/")
    CYC = Namespace("http://opencyc.sourceforge.net/daml/cyc.daml#")
    print "Image Annotation Tool"
    print "Enter the URI of a photo to annotate:"
    uri = raw_input("> ")
    mem_model.add((URIRef(uri),
                   URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                   URIRef("http://xmlns.com/foaf/0.1/Image")))
    print "Should I add a thumbnail for this image, by adding '.sized' before the extension?"
    thumbnail = raw_input("> ")
    if thumbnail:

if not form.has_key('description'):
    print 'Content-Type: text/html\r'
    print '\r'
    print "<H1>Error</H1>"
    print "Please fill in the 'description' field with an appropriate Turtle graph."

else:
    tmpfile = mkstemp()[1]
    data = convert(form['description'].value,
                   'turtle',
                   'ntriples',
                   infile=tmpfile)

    graph = TripleStore()
    graph.parse(StringIO(data), format='nt')

    thisURI = URIRef('http://%s%s' %
                     (os.environ['HTTP_HOST'], os.environ['REQUEST_URI']))

    graphNode = URIRef('file://%s' % tmpfile)

    FOAF = Namespace("http://xmlns.com/foaf/0.1/")

    try:
        bnode = graph.objects(graphNode, FOAF["primaryTopic"]).next()
    except StopIteration:
        print 'Content-Type: text/plain\r'
        print '\r'
        print 'no primary topic given'