logo

Social  Web:  Where  are  the  Semantics?

Tutorial within the ESWC 2014



Code Snippets: Data modelling

Task 1: Triplification of Twitter information

In this excersise we will provide a small program to transform Twitter data into SIOC format. We will discuss how the mapping is done as well as the difficulties and advantages of using SIOC to formalise Twitter content

We have prepared some easy code for you to play with :) The SIOC Twitter parser is available at SIOCTwitterParserGist This Gists contains three main files:

  • SIOCTWitterParser.java: contains the code that you need to parse Twitter data and transform it into SIOC format
  • pom.xml: contains the dependencies. If you prefer not to use a maven project, just go to jena and JSON-Lib and download the corresponding libraries
  • siocTwitterParser.properties: this is the properties file that you need to set up, including
    • siocOntologyFolder. This is the local folder in your computer where you store the SIOC ontology
    • jsonInputFile. This is an example of a Twitter JSON file. Note that you can can directly connect, download Twitter data and transform it! :)
    • rdfOutputFile. This is the output file containing SIOC transformed Twitter data

Just for you to understand a bit the code, tranforming data into SIOC is not that complicated :) Just load the SIOC model, choose the classes and properties that you want to model your data and do it! Below it is a small example of how to model users by using the SIOC classes and properties

    Resource userResource = this.model.createResource(BASE_URL + "user/" + id_user_str);
    userResource.addProperty(RDF.type, this.siocModel.getResource(SIOC_NS + "UserAccount"));
    userResource.addProperty(this.siocModel.getProperty(SIOC_NS + "creator_of"), postResource);
    postResource.addProperty(this.siocModel.getProperty(SIOC_NS + "has_creator"), userResource);
    userResource.addProperty(this.siocModel.getProperty(SIOC_NS + "name"), screen_name);
    userResource.addProperty(this.siocModel.getProperty(SIOC_NS + "title"), name);
    userResource.addProperty(this.siocModel.getProperty(DCTERMS_NS + "created"), user_created_at);
    userResource.addProperty(this.siocModel.getProperty(SIOC_NS + "note"), description);
    userResource.addProperty(this.siocModel.getProperty(SIOC_NS + "avatar"), url_user);

License: The contents in this page are licensed under a CC-BY license. Disclaimer We provide this code without any warranty. Use it at your own risk.

Photo used under Creative Commons CC-BY license from youasamachine