Code Monkey home page Code Monkey logo

sparql-osc's Introduction

SPARQL-OSC logo

Welcome to SPARQL-OSC, a simple multimedia messaging extension for the Semantic Web. Read on for an overview of the technique and the reference implementation.

SPARQL

The SPARQL protocol and RDF query language provides the most standard way of searching over Semantic Web data. For example, this query matches RDF data about geo-tagged blog or microblog posts:

PREFIX sioc: <http://rdfs.org/sioc/ns#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geonames: <http://www.geonames.org/ontology#>
SELECT ?long ?lat ?country ?content WHERE {
    ?post sioc:content ?content .
    ?post geo:location ?loc .
    ?loc geonames:countryCode ?country .
    ?loc geo:long ?long .
    ?loc geo:lat ?lat .
}

In evaluating a query, a SPARQL query engine produces any number of tuples which bind specific values to the variables named in the query, e.g.

long : 2.916667
lat : 51.233333
country : "BE"
content : "Wondering how I got here."

There are even ways to evaluate SPARQL queries over streams of RDF data in near-real time. See, for example, C-SPARQL, Streaming SPARQL and sparqlPuSH. As new data comes in, new results are generated and pushed to the data consumer.

OSC

Open Sound Control is an efficient messaging protocol which is the emerging standard for real-time communication among multimedia devices and software. OSC messages contain an address pattern for the recipient of the message, as well as any number of data-typed arguments. For example, a certain OSC message might report the position and pressure of a finger on an XY pad:

/myinterface/sensors/xy1 88 14 0.99

Other messages might tell a robotic arm to move to a particular position in space, a speech synthesizer to say the word “Belgium”, or an LED display to light up the number “42”.

So, what if Semantic Web events could trigger OSC messages? For the microblogging example above, that might look something like this:

/sparql-osc/test/geotweets 2.916667 51.233333 "BE" "Wondering how I got here."

Depending on the kind of data available, we can control OSC-enabled software and hardware in ways which take advantage of the expressive power of SPARQL and the ever-expanding cloud of machine-friendly knowledge on the Web.

SPARQL-OSC

It’s actually very easy to translate SPARQL results to OSC messages. All we need is an OSC address pattern as well as a pairwise mapping of SPARQL variables to abstract OSC arguments, including the names of the variables, the data types of the arguments, and the order of arguments. OSC’s atomic data types are compatible with a subset of the XML Schema datatypes:

OSC data type XML Schema types
int32 xsd:integer and its derivatives
float32 xsd:float, xsd:double
OSC-string xsd:string (1)
OSC-blob xsd:string

1 URIs, plain literals, and typed literals with data types not otherwise mentioned can also be mapped to OSC-string.

Now, making an RDF stream into an OSC stream can proceed in as little as two steps:

  1. Instantiate a listener to evaluate SPARQL queries against an RDF data source and generate OSC messages
  2. Register a SPARQL-to-OSC mapping with the listener, including:
    • the SPARQL query
    • the arguments definition
    • a network address, port, and OSC address pattern for the recipient(s) of the message

Once a mapping has been registered with the listener, downstream OSC clients will receive generated messages in as close to real-time as the SPARQL query mechanism allows.

A Java implementation

The source code available here on GitHub uses OpenRDF and JavaOSC for an extensible implementation of the above. At present, there is just one kind of listener, which simulates a continuous SPARQL query engine by polling a triple store at regular intervals. Here is a usage example:

// Instantiate a listener
SparqlOscListener l = new PollingSparqlOscListener(store.getSail(), 10000);
// Define the mapping
String query = "PREFIX sioc: <http://rdfs.org/sioc/ns#>\n" +
        "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n" +
        "PREFIX geonames: <http://www.geonames.org/ontology#>\n" +
        "SELECT ?long ?lat ?country ?content WHERE {\n" +
        "    ?post sioc:content ?content .\n" +
        "    ?post geo:location ?loc .\n" +
        "    ?loc geonames:countryCode ?country .\n" +
        "    ?loc geo:long ?long .\n" +
        "    ?loc geo:lat ?lat .\n" +
        "}";
InetAddress address = Inet6Address.getLocalHost();
int port = 5432;
String pattern = "/sparql-osc/test/geotweets";
SparqlOscMapping m = new SparqlOscMapping(query, address, port, pattern);
m.addVariable("long", OscType.FLOAT32);
m.addVariable("lat", OscType.FLOAT32);
m.addVariable("country", OscType.STRING);
m.addVariable("content", OscType.STRING);
// Register the mapping
l.register(m);

If you use Maven, you can import SPARQL-OSC like so:

<repositories>
    <repository>
        <id>fortytwo</id>
        <name>fortytwo.net Maven repository</name>
        <url>http://fortytwo.net/maven2</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>net.fortytwo</groupId>
        <artifactId>sparql-osc</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

Please see the API documentation for more details.

sparql-osc's People

Contributors

joshsh avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.