0

I have a rdf file that looks like this:

<rdf:Description rdf:about="http://sentic.net/api/en/concept/a_little">
        <rdf:type rdf:resource="http://sentic.net/api/concept"/>
        <text xmlns="http://sentic.net/api">a little</text>
        <semantics xmlns="http://sentic.net/api" rdf:resource="http://sentic.net/api/en/concept/least"/>
        <semantics xmlns="http://sentic.net/api" rdf:resource="http://sentic.net/api/en/concept/little"/>
        <semantics xmlns="http://sentic.net/api" rdf:resource="http://sentic.net/api/en/concept/small_amount"/>
        <semantics xmlns="http://sentic.net/api" rdf:resource="http://sentic.net/api/en/concept/shortage"/>
        <semantics xmlns="http://sentic.net/api" rdf:resource="http://sentic.net/api/en/concept/scarce"/>
        <pleasantness xmlns="http://sentic.net/api" rdf:datatype="http://www.w3.org/2001/XMLSchema#float">-0.99</pleasantness>
        <attention xmlns="http://sentic.net/api" rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0</attention>
        <sensitivity xmlns="http://sentic.net/api" rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0</sensitivity>
        <aptitude xmlns="http://sentic.net/api" rdf:datatype="http://www.w3.org/2001/XMLSchema#float">-0.709</aptitude>
        <polarity xmlns="http://sentic.net/api" rdf:datatype="http://www.w3.org/2001/XMLSchema#float">-0.566</polarity>
    </rdf:Description>

How can I get the object of e.g. the predicate 'polarity' (i.e. -0.566 in this case)?

cirnelle
  • 59
  • 3
  • 8

1 Answers1

0

You might want to review the getting started docs for RDFLib.

Your code could look something like this:

import rdflib

g = rdflib.Graph()

result = g.parse("yourfile.rdf")

pred = URIRef("http://sentic.net/apipoloarity")

for polarity in g.objects(predicate=pred):
    print(polarity)
Ted Lawless
  • 830
  • 6
  • 6
  • I ended up doing just that. It was the URIRef("http://sentic.net/apipoloarity") that did the trick for me. Thanks a lot! – cirnelle Feb 08 '16 at 21:43