Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add examples

  • Loading branch information...
commit 0e51916107cb8b00c9ba7858700ad715c5b6a0f0 1 parent 2e870c3
@baxtree authored
Showing with 54 additions and 15 deletions.
  1. +11 −8 README.md
  2. +43 −7 example/example.js
View
19 README.md
@@ -10,20 +10,23 @@ Add node-rdf2json module to your require path:
Generate JSON based on a URL:
- rdf2json.rdf2json.convertURLIntoRDFJSON(url, format, function(err, json){
- ...
+ rdf2json.rdf2json.convertURLIntoRDFJSON(url, format, function(err, rdfjson){
+ var obj = eval("(" + rdfjson + ")");
+ sys.puts(sys.inspect(obj));
});
Generate JSON from an RDF file:
- rdf2json.convertFileIntoRDFJSON(filepath, format, function(err, json){
- ...
+ rdf2json.convertFileIntoRDFJSON(filepath, format, function(err, rdfjson){
+ var obj = eval("(" + rdfjson + ")");
+ sys.puts(sys.inspect(obj));
});
Generate JSON from a RDF string:
- rdf2json.convertStringIntoRDFJSON(str, format, function(err, json){
- ...
+ rdf2json.convertStringIntoRDFJSON(str, format, function(err, rdfjson){
+ var obj = eval("(" + rdfjson + ")");
+ sys.puts(sys.inspect(obj));
});
#Supported RDF/JSON formats
@@ -34,7 +37,7 @@ As the time of the last release, there is no "standard" mapping between RDF and
example:
- rdf2json.convertFileIntoRDFJSON("../wine.rdf", "flat", function(err, rdfjson){
+ rdf2json.convertFileIntoRDFJSON("./test/wine.rdf", "flat", function(err, rdfjson){
// do something with rdfjson
});
@@ -58,7 +61,7 @@ exmaple:
" <!ENTITY owl \"http://www.w3.org/2002/07/owl#\" >" +
" <!ENTITY xsd \"http://www.w3.org/2001/XMLSchema#\" >" +
"]>" +
- "..." +
+ ...
"</rdf:RDF>", "talis", function(err, rdfjson){
// do something with rdfjson
});
View
50 example/example.js
@@ -1,10 +1,46 @@
var rdf2json = require("../lib/rdf2json");
var sys = require("sys");
-rdf2json.convertFileIntoRDFJSON("../myfoaf.rdf", "talis", function(err, rdfjson){
-// sys.puts(rdfjson);
-// var jsonobj = eval("("+ rdfjson +")");
-// sys.puts(JSON.stringify(jsonobj));
+rdf2json.convertFileIntoRDFJSON("./test/wine.rdf", "flat", function(err, rdfjson){
+ var obj = eval("("+ rdfjson +")");
+ sys.puts(JSON.stringify(obj));
});
-//rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "talis", function(err, rdfjson){
-// sys.debug("result: " + rdfjson);
-//});
+
+rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "sparql", function(err, rdfjson){
+ var obj = eval("("+ rdfjson +")");
+ sys.puts(JSON.stringify(obj));
+});
+
+rdf2json.convertStringIntoRDFJSON("" +
+ "<?xml version=\"1.0\"?>" +
+ " <!DOCTYPE rdf:RDF [" +
+ " <!ENTITY vin \"http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#\" >" +
+ " <!ENTITY food \"http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#\" >" +
+ " <!ENTITY owl \"http://www.w3.org/2002/07/owl#\" >" +
+ " <!ENTITY xsd \"http://www.w3.org/2001/XMLSchema#\" >" +
+ "]>" +
+ "<rdf:RDF" +
+ " xmlns = \"http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#\"" +
+ " xmlns:vin = \"http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#\"" +
+ " xml:base = \"http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#\"" +
+ " xmlns:food= \"http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#\"" +
+ " xmlns:owl = \"http://www.w3.org/2002/07/owl#\"" +
+ " xmlns:rdf = \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" +
+ " xmlns:rdfs= \"http://www.w3.org/2000/01/rdf-schema#\"" +
+ " xmlns:xsd = \"http://www.w3.org/2001/XMLSchema#\">" +
+ "" +
+ " <owl:Ontology rdf:about=\"\">" +
+ " <rdfs:comment>An example OWL ontology</rdfs:comment>" +
+ " <owl:priorVersion>" +
+ " <owl:Ontology rdf:about=\"http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine\"/>" +
+ " </owl:priorVersion>" +
+ " <owl:imports rdf:resource=\"http://www.w3.org/TR/2003/PR-owl-guide-20031209/food\"/>" +
+ " <rdfs:comment>Derived from the DAML Wine ontology at " +
+ " http://ontolingua.stanford.edu/doc/chimaera/ontologies/wines.daml" +
+ " Substantially changed, in particular the Region based relations." +
+ " </rdfs:comment>" +
+ " <rdfs:label>Wine Ontology</rdfs:label>" +
+ " </owl:Ontology>" +
+ "</rdf:RDF>", "talis", function(err, rdfjson){
+ var obj = eval("("+ rdfjson +")");
+ sys.puts(JSON.stringify(obj));
+});
Please sign in to comment.
Something went wrong with that request. Please try again.