Successfully reported this slideshow.

rdfapi.js and js3.js by webr3

1

Share

1 of 24
1 of 24

rdfapi.js and js3.js by webr3

1

Share

Download to read offline

Transcript

  1. 1. $ git clone https://github.com/webr3/js3.git $ git checkout origin/rdfa-api-integration <script type=”text/javascript” src=”js3.js”></script> var js3 = require(‘./js3.node.js’);
  2. 2. var context = new rdfapi.Context(); var parser = new rdfapi.parsers.Turtle(context); var serializer = new rdfapi.serializers.Turtle(context); var turtle_text = ‘@prefix ex: <http://example.com/people/> .¥ @prefix foaf: <http://xmlns.com/foaf/0.1/> .¥ ¥ ex:taro a foaf:Person;¥ foaf:name “Taro”;¥ foaf:age 25 .’; parser.parse(turtle_text, function(graph){ console.log(serializer.serialize(graph)); });
  3. 3. parser.parse(turtle_text, function(graph){ graph.forEach(function(triple){ // show each triples console.log(triple.toString()); }) graph.add(triple2); // add a triple to the graph // use filter var filter = rdfapi.filters.p(“owl:sameAs”); graph.some(filter); graph.every(filter); graph.filter(filter); graph.merge(other_graph); });
  4. 4. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
  5. 5. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
  6. 6. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
  7. 7. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
  8. 8. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3()); ↓
  9. 9. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3()); ↓ <http://example.com/rdf/taro> rdf:type foaf:Person; foaf:name “Taro Yamada”; foaf:age 27; foaf:homepage <http://example.com/home/taro> .
  10. 10. // TypedLiteral .type IRI ( CURIE ) (true).type; //=> xsd:boolean (new Date()).type; //=> xsd:dateTime (10).type; //=> xsd:integer (3.14).type; //=> xsd:decimal // .nodeType() TypedLiteral, PlainLiteral, BlankNode, IRI (10).nodeType(); //=> TypedLiteral “hello”.nodeType(); //=> PlainLiteral “_:b12”.nodeType(); //=> BlankNode “foaf:name”.nodeType(); //=> IRI “http://example.com/”.nodeType(); //=> IRI
  11. 11. // foaf:name 2 var me1 = { “foaf:nick”: [“nick”, “name”] }.ref(); // RDF List var me2 = { “foaf:nick”: [“nick”, “name”].toList() }.ref();
  12. 12. var taro = { name: “Taro”, holdsAccount: { accountName: ‘xxx’, homepage: ‘http://twitter.com/xxx’, } }.ref(“:taro”); var jiro = { “foaf:knows”: taro }.ref(“:jiro”);
  13. 13. var me = { name: “Taro”, age: 27 }.ref(“:me”); console.log(typeof me.age); //=> number console.log((new Date()).getFullYear() - me.age); //=> 1984 console.log(me.name.toUpper()); //=> “TARO”
  14. 14. // parsing by rdfapi.js parser.parse(“SOME RDF STRING”, function(graph){ var data = { a: “foaf:Document”, ..., }.ref(“:book”); graph.merge(data.graphify()); // });

Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    1. 1. $ git clone https://github.com/webr3/js3.git $ git checkout origin/rdfa-api-integration <script type=”text/javascript” src=”js3.js”></script> var js3 = require(‘./js3.node.js’);
    2. 2. var context = new rdfapi.Context(); var parser = new rdfapi.parsers.Turtle(context); var serializer = new rdfapi.serializers.Turtle(context); var turtle_text = ‘@prefix ex: <http://example.com/people/> .¥ @prefix foaf: <http://xmlns.com/foaf/0.1/> .¥ ¥ ex:taro a foaf:Person;¥ foaf:name “Taro”;¥ foaf:age 25 .’; parser.parse(turtle_text, function(graph){ console.log(serializer.serialize(graph)); });
    3. 3. parser.parse(turtle_text, function(graph){ graph.forEach(function(triple){ // show each triples console.log(triple.toString()); }) graph.add(triple2); // add a triple to the graph // use filter var filter = rdfapi.filters.p(“owl:sameAs”); graph.some(filter); graph.every(filter); graph.filter(filter); graph.merge(other_graph); });
    4. 4. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
    5. 5. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
    6. 6. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
    7. 7. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3());
    8. 8. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3()); ↓
    9. 9. var taro = { a: “foaf:Person”, name: “Taro Yamada”, age: new Date().getFullYear() - 1984, homepage: “http://example.com/home/taro” }.ref(“http://example.com/rdf/taro”); console.log(taro.n3()); ↓ <http://example.com/rdf/taro> rdf:type foaf:Person; foaf:name “Taro Yamada”; foaf:age 27; foaf:homepage <http://example.com/home/taro> .
    10. 10. // TypedLiteral .type IRI ( CURIE ) (true).type; //=> xsd:boolean (new Date()).type; //=> xsd:dateTime (10).type; //=> xsd:integer (3.14).type; //=> xsd:decimal // .nodeType() TypedLiteral, PlainLiteral, BlankNode, IRI (10).nodeType(); //=> TypedLiteral “hello”.nodeType(); //=> PlainLiteral “_:b12”.nodeType(); //=> BlankNode “foaf:name”.nodeType(); //=> IRI “http://example.com/”.nodeType(); //=> IRI
    11. 11. // foaf:name 2 var me1 = { “foaf:nick”: [“nick”, “name”] }.ref(); // RDF List var me2 = { “foaf:nick”: [“nick”, “name”].toList() }.ref();
    12. 12. var taro = { name: “Taro”, holdsAccount: { accountName: ‘xxx’, homepage: ‘http://twitter.com/xxx’, } }.ref(“:taro”); var jiro = { “foaf:knows”: taro }.ref(“:jiro”);
    13. 13. var me = { name: “Taro”, age: 27 }.ref(“:me”); console.log(typeof me.age); //=> number console.log((new Date()).getFullYear() - me.age); //=> 1984 console.log(me.name.toUpper()); //=> “TARO”
    14. 14. // parsing by rdfapi.js parser.parse(“SOME RDF STRING”, function(graph){ var data = { a: “foaf:Document”, ..., }.ref(“:book”); graph.merge(data.graphify()); // });

    Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • More Related Content

    Related Books

    Free with a 30 day trial from Scribd

    See all

    ×