This is an open-source javascript library for building Semantic Web and Linked Data application, similar to OWL API and Jena API.
This library is not dependant to anything whatsoever. It is lightweight, easy to install and easy to use. It adpots the UMD (Universal Module Definition) standards, which makes it compatible with AMD, CommonJS / Node.JS and Plain Browser Loading.
The documentations are auto-generated by the Grunt YUIDocs plugin. It is located in the dist/docs/
directory. When grunt
command is runned everytime, the docs are re-generated and placed into the dist directory.
The full documentation has been deployed to my server and could be reached at semanticjs.oguzgelal.com.
The node_modules directory which contains all the third party plugins (that are necessary for build process only, not included in the library) is ignored. So after cloning the project, running (sudo) npm install
is needed. After that, all you need to do is to run grunt
command.
All the building process is handled by Grunt. It compresses, optimizes and minifies all the modular javascript structure, and places in the dist/
directory. The output of library is only one lightweight file, semantic.min.js (or semantic.js which is the non-minified version).
The full documentation has been deployed to my server and could be reached at semanticjs.oguzgelal.com.
Before creating any ontologies, you should start with initialising the Semant
object.
var semantics = new Semant();
Semant object is the global namespace of this API. With this var, you control global stuff that aren't related to any specific dataset. Such as debug mode:
semantics.setDebug(true);
Debug variable already defults to true
. Basically, it enables and disables all the console.logs()
's through out the API.
You also create ontologies from the Semant object.
var people = semantics.createOntology("People", "http://ppl.com");
Every ontology must have a name and a unique domain. URI's will be generated with these info. If something goes wrong while creating ontology, createOntologyException
will be thworn. Once you create an ontology, you can now create an entity under an ontology:
var male = people.createEntity("Male");
var female = people.createEntity("Female");
or another way to create entities are calling the createSubEntity
method. This method is equivalent to createEntity
, but it is not called from an ontology, it is called directly from an entity. Another difference is that it sets some fields of the entity in such a way that the newly created entity becomes the sub-entity of the entity in context.
var alive = semantics.createOntology("Alive", "http://ppl.com");
var human = alive.createEntity("Human");
var male = human.createSubEntity("Male");
var female = human.createSubEntity("Female");
you can also use the makeSubEntity
method to do the same thing. The code block above does exactly the same thing as this:
var alive = semantics.createOntology("Alive", "http://ppl.com");
var human = alive.createEntity("Human");
var male = alive.createEntity("Male");
var female = alive.createEntity("Female");
male.makeSubEntity(human);
female.makeSubEntity(human);
As in Ontologies, every entity must have a unique name so that unique URI's could be created. If anything goes wrong, createEntityException
will be thrown.
Literals are created under ontologies. They don't need a unique name. They are easy to manage and create. Their unique ID, URI and type are auto-generated by the time the literal object is created. Here is an example:
var people = semantics.createOntology("People", "http://ppl.com");
// create entities
var male = people.createEntity("Male");
var oguz = male.createSubEntity("Oguz");
// create relations
var bornIn = ppl.createRelation("bornIn");
// create literals
var oguzYear = ppl.createLiteral(1993);
// see the Relation section
oguz.addRelation(bornIn, oguzYear);
Relations are also created under ontologies. Once they are created, they are assigned to entities. They could be created with createRelation
method of the Ontology objects.
var semantics = new Semant();
var geo = semantics.createOntology("Geo", "http://geo.com");
var inLocation = geo.createRelation("in");
Here, we created an inLocation relationship under geo Ontology. After we created relations, we can assign it to entities with the addRelations
method called from Entity objects.
var semantics = new Semant();
var geo = semantics.createOntology("Geo", "http://geo.com");
var inLocation = geo.createRelation("in");
var turkey = geo.createEntity("Turkey");
var istanbul = geo.createEntity("Istanbul");
istanbul.addRelation(inLocation, turkey);
Above, we created turkey and istanbul entity, and inLocation relationship. We assigned the in property in such a way that it binds istanbul entity to turkey entity. The relOut variable of istanbul looks like [[inLocation, turkey]]
and relIn variable or turkey looks like [[inLocation, istanbul]]
.
All the exceptions inherits from Exception
class at Core/Exception/Exception.js. They have code
, name
, notice
(what happened) and message
(what caused it). All exceptions takes message
field as an argument. Other details are coded into relevant class.
All exceptions have .toString()
method which gives you the basic information about the exception, and .details()
method which gives you detailed information. If debug mode is enables, detailed version will be written on the console when thrown.
The ontologies created using this library can be exported into OWL format. The export method will return the output as String.
var semantics = new Semant();
var ontology = semantics.createOntology("SampleOnt", "http://domain.com");
// ... fill up the ontology here ...
var options = {};
var owlout = semantics.Export.exportOWL(ontology, options);