Skip to content

5 minutes HOWTO guide

chefabien edited this page Feb 23, 2016 · 14 revisions

This page shows you how to get started with AutoRDF

#Compiling from source on Debian or Ubuntu

apt-get install build-essential cmake librdf0-dev 
cmake .
make install

Write your ontology

We assume here that you already have a working OWL or RDFS file somewhere that defines your ontology. If not we suggest you start playing with some existing ontology such as FOAF, available at http://xmlns.com/foaf/spec/20140114.rdf

Start generating generating code

fchevalier@ganymede:/tmp/test$ autordfcodegen -a 20140114.rdf 
No prefix found for class http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing namespace, ignoring
Class http://xmlns.com/foaf/0.1/Person has unreachable ancestor http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing, ignoring ancestor
Property http://xmlns.com/foaf/0.1/based_near refers to unreachable rdfs class     http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing, skipping
Property http://xmlns.com/foaf/0.1/focus refers to unreachable rdfs class http://www.w3.org/2004/02/skos/core#Concept, skipping

Some warnings are printed on the output.

  • "No prefix found for class" means there is no prefix declared for this class IRI. AutoRDF requires a prefix, as it will use it as C++ namespace.
  • "Class CCCC has unreachable ancestor" means that an OWL class refers to another OWL class for which we have no definition. This case is handled by ignoring the parent/child relationship
  • "Property PPPP refers to unreachable rdfs class CCCC, skipping" means that accessors will not be generated for this class, as we have no information about that class.

Write your first program

#include <autordf/Factory.h>

#include <foaf/foaf.h>
#include <owl/owl.h>

int main(int argc, char ** argv) {
    autordf::Factory f;
    autordf::Object::setFactory(&f);

    if ( argc == 2 ) {
        f.loadFromFile(argv[1]);
    } else {
        std::cerr << "Should provide rdf file as first argument" << std::endl;
    }

    auto personList = foaf::Person::find();

    for ( const foaf::Person& person : personList ) {
        std::cout << person.nameList(); 
        if ( person.mboxList().size()  ) {
            std::cout << " {";
            for ( const owl::Thing& th: person.mboxList() ) {
                std::cout << th.iri() << ", ";
            }
            std::cout << " }";
        }
        std::cout << std::endl;
    }
}

Compile the whole thing

clang++ -std=c++11 -I. -I/usr/local/include main.cpp AllInOne.cpp -lautordf -o main

Run the example

fchevalier@ganymede:/tmp/test$ ./example <autordf source dir>/src/autordf/unittests/foafExample.rdf
Jimmy Criket
Angela Beesley
Jimmy Wales {mailto:[email protected],  }

Clone this wiki locally