Semantics Hello World

In this exercise, you will

 

  1. Insert RDF triples into a database
  2. Query the triples using SPARQL

 

This is a highly simplified example - we'll break some rules, but that's OK!

Enable the triple index

 

  1. Point your browser to the MarkLogic Administrative Interface on http://localhost:8001. (Replace localhost with the hostname).
  2. Choose the Documents database in the Databases section.
  3. In the Configure tab, scroll down the page until you see the triple index option.
  4. If the value is false, click the radio button for true to enable the triple index. If the value is already true, there is no need to change it.
  5. Click the ok button at the top of the page to save any changes.

 

Insert some triples

 

  1. Point your browser to http://localhost:8000 (Replace localhost with the hostname of your MarkLogic server if necessary). If you're doing this from a fresh install, Query Console will be pointing at the Documents database (look at the top left in the dropdown). If the Query Type is set to the default, JavaScript, the text box shows a single line with a JavaScript comment. If you change the Query Type to XQuery a "hello world" XQuery example displays in the text area. Both XQuery and JavaScript examples are given so select which one you would like in the Query Type dropdown.
  2. Remove any code from the text box.
  3. Paste this into the text box and hit "run":

    Here, you are inserting 3 triples. Each triple is of the form ("subject", "predicate", "object") where the subject and predicate are IRIs (like URIs, but internationalized) and the object is, in this case, a simple string. It will generate output, something like

 

Verify triple count

Check that you have some triples.

 

  1. In Query Console, click "+" to open a new tab.
  2. Select XQuery or JavaScript as a Query Type and remove any code from the text box.
  3. Paste this query into the text box and hit "run":

    It should return

 

Run a SPARQL Query

Let's run a query that asks, "Who lives in London?".

 

  1. In Query Console, click "+" to open a new tab.
  2. Select XQuery or JavaScript as a Query Type and remove any code from the text box.
  3. Paste this query into the text box and hit "run":

    It should return

 

Next Steps

Congratulations! You inserted 3 triples into a MarkLogic database and ran a SPARQL query.

Want to do more? Try these:

Run SPARQL directly in Query Console

In Query Console, select "Query Type" = SPARQL, and type in SPARQL queries

Create and insert lots of triples

See documentation for sem:rdf-builder() (XQuery) or sem.rdfBuilder() (JavaScript)

Load triples from a file

References

 

 

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.