Tutorial: How to call a NIF web service with your favorite SemWeb library

The parameters for NIF 1.0 can be found in the Parameter Section of the spec.
Below are example code snippets for several client side implementations. The result is always a combined RDF model of two NIF services.

curl

Note that there currently is no “best” RDF merge tool for the so we will use Jena CLI.

# query snowball demo webservice
curl "http://nlp2rdf.lod2.eu/demo/NIFStemmer?input=My%20favorite%20actress%20is%20Natalie%20Portman!&input-type=text&nif=true" > snowball.owl
# query stanford demo webservice
curl "http://nlp2rdf.lod2.eu/demo/NIFStanfordCore?input=My%20favorite%20actress%20is%20Natalie%20Portman!&input-type=text&nif=true" > stanford.owl
#combine with Jena rdfcat
rdfcat -x snowball.owl stanford.owl > combined.owl

Jena

See http://jena.sourceforge.net


Model model = ModelFactory.createDefaultModel();
String text = "My favorite actress is Natalie Portman!"
StringBuilder p = new StringBuilder();
p.append("?input=");
p.append(URLEncoder.encode(text,"UTF-8"));
p.append("&input-type=text");
p.append("&nif=true");
URL stemmer = new URL("http://nlp2rdf.lod2.eu/demo/NIFStemmer"+p.toString());
URL stanford = new URL("http://nlp2rdf.lod2.eu/demo/NIFStanfordCore"+p.toString());
model.read(
   new BufferedReader(new InputStreamReader(stemmer.openConnection().getInputStream())), null);
model.read(
   new BufferedReader(new InputStreamReader(stanford.openConnection().getInputStream())), null);

ARC2

See . This is also the code used in this .


$stemmer = "http://nlp2rdf.lod2.eu/demo/NIFStemmer?input-type=text&nif=true&input=".urlencode($text);
$parser = ARC2::getRDFXMLParser();
$parser->parse($stemmer);
$stemmertriples = $parser->getTriples();
$stanford = "http://nlp2rdf.lod2.eu/demo/NIFStanfordCore?input-type=text&nif=true&input=".urlencode($text);
$parser = ARC2::getRDFXMLParser();
$parser->parse($stanford);
$stanfordtriples = $parser->getTriples();
$alltriples = array_merge($stanfordtriples, $stemmertriples);
$ser = ARC2::getTurtleSerializer();
$output = $ser->getSerializedTriples($alltriples);
echo $output;
This entry was posted in Tutorials. Bookmark the permalink.

Comments are closed.