Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improved codes from CLOUD9

  • Loading branch information...
commit c4cf8b4e723160ceea5a5c2976287c085c1a2196 1 parent 6be0cd7
@baxtree authored
View
92 example/example.js
@@ -1,46 +1,48 @@
-var rdf2json = require("../lib/rdf2json");
-var sys = require("sys");
-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", "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));
+var rdf2json = require("../lib/rdf2json");
+var sys = require("sys");
+rdf2json.convertFileIntoRDFJSON("./test/wine.rdf", "flat", function(err, rdfjson){
+ if(err) sys.puts("Something wrong here ...");
+ var obj = eval("("+ rdfjson +")");
+ sys.puts(JSON.stringify(obj));
+});
+
+rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "sparql", function(err, rdfjson){
+ if(err) sys.puts("Something wrong here ...");
+ 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));
});
View
2  lib/rdf2json/index.js
@@ -1,2 +1,2 @@
-var rdf2json = require("./node-rdf2json");
+var rdf2json = require("./node-rdf2json");
module.exports = rdf2json;
View
297 lib/rdf2json/node-rdf2json.js
@@ -1,150 +1,149 @@
-var http = require("http");
-var sys = require("sys");
-var RDF = require("../vendor/rdf-parser/parser").RDF;
-var fs = require("fs");
-
-function generateFlatRDFJSONString(triples) {
- var rdfjson = "";
- for ( var i = 0; i < triples.length; i++) {
- rdfjson += "{";
- var subject = triples[i].subject.toString();
- var predicate = triples[i].predicate.toString();
- var object = triples[i].object == undefined ? undefined
- : triples[i].object.toString();
- var lang = triples[i].lang ? triples[i].lang.toString() : "";
- var datatype = triples[i].datatype ? triples[i].datatype.toString()
- : "";
- if (triples[i].type == "resource") {
- rdfjson += "\"s\" : { \"type\" : \"uri\", \"uri\" : \"" + subject
- + "\" },";
- rdfjson += "\"p\" : \"" + predicate + "\",";
- rdfjson += "\"o\" : { \"type\" : \"uri\", \"uri\" : \"" + object
- + "\" }";
- } else {
- rdfjson += "\"s\" : { \"type\" : \"uri\", \"uri\" : \"" + subject
- + "\" },";
- rdfjson += "\"p\" : \"" + predicate + "\",";
- rdfjson += "\"o\" : { \"type\" : \"literal\", \"val\" : \""
- + object + "\" , \"lang\" : \"" + lang
- + "\", \"datatype\" : \"" + datatype + "\"}";
- }
- if (i != (triples.length - 1)) {
- rdfjson += "},";
- } else {
- rdfjson += "}";
- }
- }
- return rdfjson;
-}
-
-function _toRDFJSON(rdf, type, callback) {
- var rdfjson = "";
- if (type.toLowerCase() == "flat") {
- var triples = rdf.Match(null, null, null, null);
- rdfjson += "{ \"data\" : [";
- rdfjson += generateFlatRDFJSONString(triples);
- rdfjson += "]}";
- } else if (type.toLowerCase() == "sparql") {
- var triples = rdf.Match(null, null, null, null);
- rdfjson += "{ \"head\" : { \"vars\" : [\"s\", \"p\", \"o\"]},";
- rdfjson += "\"results\" : { \"bindings\" : [";
- rdfjson += generateFlatRDFJSONString(triples);
- rdfjson += "]}}";
- } else if (type.toLowerCase() == "talis") {
- var triples = rdf.Match(null, null, null, null);
- sys.puts(sys.inspect(triples));
- var subjects = new Array();
- for ( var i = 0; i < triples.length; i++) {
- if (subjects.indexOf(triples[i].subject) != -1) {
- continue;
- } else {
- subjects.push(triples[i].subject);
- }
- }
- rdfjson += "{";
- for ( var i = 0; i < subjects.length; i++) {
- rdfjson += " \"" + subjects[i] + "\" : {";
- var groupSubjects = rdf.Match(null, subjects[i], null, null);
- var predicates = new Array();
- for ( var j = 0; j < groupSubjects.length; j++) {
- if (predicates.indexOf(groupSubjects[j].predicate) != -1) {
- continue;
- } else {
- predicates.push(groupSubjects[j].predicate);
- }
- }
- for ( var j = 0; j < predicates.length; j++) {
- rdfjson += "\"" + predicates[j] + "\" : [";
- groupObjects = rdf
- .Match(null, subjects[i], predicates[j], null);
- for ( var k = 0; k < groupObjects.length; k++) {
- var object = groupObjects[k].object;
- if (!groupObjects[k].type)
- continue;// TODO If the parsing result is correct,
- // each statement should always have this
- // type info.
- if (groupObjects[k].type.toString() == "literal") {
- rdfjson += "{ \"value\" : \"" + object.toString()
- + "\", \"type\" : \"uri\"";
- if (groupObjects[k].datatype) {
- rdfjson += ", \"datatype\" : \""
- + groupObjects[k].datatype.toString()
- + "\"";
- }
- if (groupObjects[k].lang) {
- rdfjson += ", \"lang\" : \""
- + groupObjects[k].lang.toString() + "\"";
- }
- rdfjson += "}";
- } else if (groupObjects[k].type.toString() == "resource") {
- if (object.toString().substr(0, 2) == "_:n") {
- rdfjson += "{ \"value\" : \"" + object.toString()
- + "\", \"type\" : \"bnode\"}";
- } else {
- rdfjson += "{ \"value\" : \"" + object.toString()
- + "\", \"type\" : \"uri\"}";
- }
- }
- if (k < groupObjects.length - 1) {
- rdfjson += ",";
- }
- }
- rdfjson += "]";
- if (j < predicates.length - 1)
- rdfjson += ",";
- }
- rdfjson += "}";
- if (i < subjects.length - 1)
- rdfjson += ",";
- }
- rdfjson += "}";
- }
- callback(null, rdfjson);
-}
-
-exports.convertStringIntoRDFJSON = function(rdfxml, type, callback) {
- var rdf = new RDF();
- rdf.loadRDFXML(rdfxml);
- _toRDFJSON(rdf, type, function(err, rdfjson) {
- callback(null, rdfjson);
- });
-};
-
-exports.convertFileIntoRDFJSON = function(filepath, type, callback) {
- var self = this;
- var rdf = new RDF();
- fs.readFile(filepath, function(err, data) {
- self.convertStringIntoRDFJSON(data, type, function(err, rdfjson) {
- callback(null, rdfjson);
- });
- });
-};
-
-exports.convertURLIntoRDFJSON = function(url, type, callback) {
- var rdf = new RDF();
- rdf.getRDFURL(url, function() {
- _toRDFJSON(rdf, type, function(err, rdfjson) {
- callback(null, rdfjson);
- });
- });
+var sys = require("sys");
+var RDF = require("../vendor/rdf-parser/parser").RDF;
+var fs = require("fs");
+
+function generateFlatRDFJSONString(triples) {
+ var rdfjson = "";
+ for ( var i = 0; i < triples.length; i++) {
+ rdfjson += "{";
+ var subject = triples[i].subject.toString();
+ var predicate = triples[i].predicate.toString();
+ var object = triples[i].object == undefined ? undefined
+ : triples[i].object.toString();
+ var lang = triples[i].lang ? triples[i].lang.toString() : "";
+ var datatype = triples[i].datatype ? triples[i].datatype.toString()
+ : "";
+ if (triples[i].type == "resource") {
+ rdfjson += "\"s\" : { \"type\" : \"uri\", \"uri\" : \"" + subject
+ + "\" },";
+ rdfjson += "\"p\" : \"" + predicate + "\",";
+ rdfjson += "\"o\" : { \"type\" : \"uri\", \"uri\" : \"" + object
+ + "\" }";
+ } else {
+ rdfjson += "\"s\" : { \"type\" : \"uri\", \"uri\" : \"" + subject
+ + "\" },";
+ rdfjson += "\"p\" : \"" + predicate + "\",";
+ rdfjson += "\"o\" : { \"type\" : \"literal\", \"val\" : \""
+ + object + "\" , \"lang\" : \"" + lang
+ + "\", \"datatype\" : \"" + datatype + "\"}";
+ }
+ if (i != (triples.length - 1)) {
+ rdfjson += "},";
+ } else {
+ rdfjson += "}";
+ }
+ }
+ return rdfjson;
+}
+
+function _toRDFJSON(rdf, type, callback) {
+ var rdfjson = "";
+ if (type.toLowerCase() == "flat") {
+ var triples = rdf.Match(null, null, null, null);
+ rdfjson += "{ \"data\" : [";
+ rdfjson += generateFlatRDFJSONString(triples);
+ rdfjson += "]}";
+ } else if (type.toLowerCase() == "sparql") {
+ var triples = rdf.Match(null, null, null, null);
+ rdfjson += "{ \"head\" : { \"vars\" : [\"s\", \"p\", \"o\"]},";
+ rdfjson += "\"results\" : { \"bindings\" : [";
+ rdfjson += generateFlatRDFJSONString(triples);
+ rdfjson += "]}}";
+ } else if (type.toLowerCase() == "talis") {
+ var triples = rdf.Match(null, null, null, null);
+ sys.puts(sys.inspect(triples));
+ var subjects = new Array();
+ for ( var i = 0; i < triples.length; i++) {
+ if (subjects.indexOf(triples[i].subject) != -1) {
+ continue;
+ } else {
+ subjects.push(triples[i].subject);
+ }
+ }
+ rdfjson += "{";
+ for ( var i = 0; i < subjects.length; i++) {
+ rdfjson += " \"" + subjects[i] + "\" : {";
+ var groupSubjects = rdf.Match(null, subjects[i], null, null);
+ var predicates = new Array();
+ for ( var j = 0; j < groupSubjects.length; j++) {
+ if (predicates.indexOf(groupSubjects[j].predicate) != -1) {
+ continue;
+ } else {
+ predicates.push(groupSubjects[j].predicate);
+ }
+ }
+ for ( var j = 0; j < predicates.length; j++) {
+ rdfjson += "\"" + predicates[j] + "\" : [";
+ groupObjects = rdf
+ .Match(null, subjects[i], predicates[j], null);
+ for ( var k = 0; k < groupObjects.length; k++) {
+ var object = groupObjects[k].object;
+ if (!groupObjects[k].type)
+ continue;// TODO If the parsing result is correct,
+ // each statement should always have this
+ // type info.
+ if (groupObjects[k].type.toString() == "literal") {
+ rdfjson += "{ \"value\" : \"" + object.toString()
+ + "\", \"type\" : \"uri\"";
+ if (groupObjects[k].datatype) {
+ rdfjson += ", \"datatype\" : \""
+ + groupObjects[k].datatype.toString()
+ + "\"";
+ }
+ if (groupObjects[k].lang) {
+ rdfjson += ", \"lang\" : \""
+ + groupObjects[k].lang.toString() + "\"";
+ }
+ rdfjson += "}";
+ } else if (groupObjects[k].type.toString() == "resource") {
+ if (object.toString().substr(0, 2) == "_:n") {
+ rdfjson += "{ \"value\" : \"" + object.toString()
+ + "\", \"type\" : \"bnode\"}";
+ } else {
+ rdfjson += "{ \"value\" : \"" + object.toString()
+ + "\", \"type\" : \"uri\"}";
+ }
+ }
+ if (k < groupObjects.length - 1) {
+ rdfjson += ",";
+ }
+ }
+ rdfjson += "]";
+ if (j < predicates.length - 1)
+ rdfjson += ",";
+ }
+ rdfjson += "}";
+ if (i < subjects.length - 1)
+ rdfjson += ",";
+ }
+ rdfjson += "}";
+ }
+ callback(null, rdfjson);
+}
+
+exports.convertStringIntoRDFJSON = function(rdfxml, type, callback) {
+ var rdf = new RDF();
+ rdf.loadRDFXML(rdfxml);
+ _toRDFJSON(rdf, type, function(err, rdfjson) {
+ callback(null, rdfjson);
+ });
+};
+
+exports.convertFileIntoRDFJSON = function(filepath, type, callback) {
+ var self = this;
+ var rdf = new RDF();
+ fs.readFile(filepath, function(err, data) {
+ self.convertStringIntoRDFJSON(data, type, function(err, rdfjson) {
+ callback(null, rdfjson);
+ });
+ });
+};
+
+exports.convertURLIntoRDFJSON = function(url, type, callback) {
+ var rdf = new RDF();
+ rdf.getRDFURL(url, function() {
+ _toRDFJSON(rdf, type, function(err, rdfjson) {
+ callback(null, rdfjson);
+ });
+ });
};
View
3  lib/vendor/node-XMLHttpRequest/XMLHttpRequest.js
@@ -11,8 +11,7 @@
* @license MIT
*/
-var Url = require("url")
- ,sys = require("sys");
+var Url = require("url");
exports.XMLHttpRequest = function() {
/**
View
1  lib/vendor/rdf-parser/parser.js
@@ -56,7 +56,6 @@ Changes since 0.37 - Added postRDFURL for Carlos Strozzi
/*extern ActiveXObject,Document,DOMParser,SVGDoc *//* platform support */
var XMLHttpRequest = require("../node-XMLHttpRequest/XMLHttpRequest").XMLHttpRequest;
-var sys = require("sys");
var xmlDOMParser = require("../node-o3-xml");
function RDF() {
View
333 test/test.js
@@ -1,164 +1,171 @@
-var rdf2json = require("../lib/rdf2json");
-var jsunit = require("mjsunit");
-
-function testConvertStringIntoRDFJSON(){
- 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>", "flat", function(err, rdfjson){
- jsunit.assertNotNull("The generated flat RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The flat RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertFileIntoRDFJSON(){
- rdf2json.convertFileIntoRDFJSON("../wine.rdf", "flat", function(err, rdfjson){
- jsunit.assertNotNull("The generated flat RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The flat RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertURLIntoRDFJSON(){
- rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "flat", function(err, rdfjson){
- jsunit.assertNotNull("The generated flat RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The flat RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertStringIntoRDFJSON(){
- 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>", "sparql", function(err, rdfjson){
- jsunit.assertNotNull("The generated SPARQL RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The SPARQL RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertFileIntoRDFJSON(){
- rdf2json.convertFileIntoRDFJSON("../wine.rdf", "sparql", function(err, rdfjson){
- jsunit.assertNotNull("The generated SPARQL RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The SPARQL RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertURLIntoRDFJSON(){
- rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "sparql", function(err, rdfjson){
- jsunit.assertNotNull("The generated SPARQL RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The SPARQL RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertStringIntoRDFJSON(){
- 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){
- jsunit.assertNotNull("The generated Talis RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The Talis RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertFileIntoRDFJSON(){
- rdf2json.convertFileIntoRDFJSON("../wine.rdf", "talis", function(err, rdfjson){
- jsunit.assertNotNull("The generated Talis RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The Talis RDF/JSON object should not be null", jsonobj);
- });
-}
-
-function testConvertURLIntoRDFJSON(){
- rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "talis", function(err, rdfjson){
- jsunit.assertNotNull("The generated Talis RDF/JSON string should not be null", rdfjson);
- var jsonobj = eval("("+ rdfjson +")");
- jsunit.assertNotNull("The Talis RDF/JSON object should not be null", jsonobj);
- });
+var rdf2json = require("../lib/rdf2json");
+var jsunit = require("mjsunit");
+var sys = require("sys");
+
+function testConvertStringIntoRDFJSON(){
+ 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>", "flat", function(err, rdfjson){
+ if(err) sys.puts("Something wrong here ...");
+ jsunit.assertNotNull("The generated flat RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The flat RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertFileIntoRDFJSON(){
+ rdf2json.convertFileIntoRDFJSON("../wine.rdf", "flat", function(err, rdfjson){
+ jsunit.assertNotNull("The generated flat RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The flat RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertURLIntoRDFJSON(){
+ rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "flat", function(err, rdfjson){
+ jsunit.assertNotNull("The generated flat RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The flat RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertStringIntoRDFJSON(){
+ 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>", "sparql", function(err, rdfjson){
+ if(err) sys.puts("Something wrong here ...");
+ jsunit.assertNotNull("The generated SPARQL RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The SPARQL RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertFileIntoRDFJSON(){
+ rdf2json.convertFileIntoRDFJSON("../wine.rdf", "sparql", function(err, rdfjson){
+ if(err) sys.puts("Something wrong here ...");
+ jsunit.assertNotNull("The generated SPARQL RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The SPARQL RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertURLIntoRDFJSON(){
+ rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "sparql", function(err, rdfjson){
+ jsunit.assertNotNull("The generated SPARQL RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The SPARQL RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertStringIntoRDFJSON(){
+ 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){
+ if(err) sys.puts("Something wrong here ...");
+ jsunit.assertNotNull("The generated Talis RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The Talis RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertFileIntoRDFJSON(){
+ rdf2json.convertFileIntoRDFJSON("../wine.rdf", "talis", function(err, rdfjson){
+ if(err) sys.puts("Something wrong here ...");
+ jsunit.assertNotNull("The generated Talis RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The Talis RDF/JSON object should not be null", jsonobj);
+ });
+}
+
+function testConvertURLIntoRDFJSON(){
+ rdf2json.convertURLIntoRDFJSON("http://www.w3.org/TR/owl-guide/wine.rdf", "talis", function(err, rdfjson){
+ if(err) sys.puts("Something wrong here ...");
+ jsunit.assertNotNull("The generated Talis RDF/JSON string should not be null", rdfjson);
+ var jsonobj = eval("("+ rdfjson +")");
+ jsunit.assertNotNull("The Talis RDF/JSON object should not be null", jsonobj);
+ });
}
Please sign in to comment.
Something went wrong with that request. Please try again.