Semantics Hello World
In this exercise, you will
- Insert RDF triples into a database
- Query the triples using SPARQL
This is a highly simplified example - we'll break some rules, but that's OK!
Enable the triple index
- Point your browser to the MarkLogic Administrative Interface on http://localhost:8001. (Replace
localhostwith the hostname). - Choose the
Documentsdatabase in the Databases section. - In the Configure tab, scroll down the page until you see the
triple indexoption. - If the value is
false, click the radio button fortrueto enable the triple index. If the value is alreadytrue, there is no need to change it. - Click the ok button at the top of the page to save any changes.
Insert some triples
- Point your browser to http://localhost:8000 (Replace
localhostwith the hostname of your MarkLogic server if necessary). If you're doing this from a fresh install, Query Console will be pointing at theDocumentsdatabase (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 toXQuerya "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. - Remove any code from the text box.
- 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.
- In Query Console, click "+" to open a new tab.
- Select XQuery or JavaScript as a Query Type and remove any code from the text box.
- 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?".
- In Query Console, click "+" to open a new tab.
- Select XQuery or JavaScript as a Query Type and remove any code from the text box.
- 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)orsem.rdfBuilder() (JavaScript) - Load triples from a file
-
- See documentation for
sem:rdf-load()(XQuery) orsem.rdfLoad()(JavaScript). If you have usedxdmp:document-load()(XQuery) orxdmp.documentLoad()(JavaScript), you may want to compare it with this function. - See mlcp - the preferred tool for bulk loads
- See documentation for
References
- Query Console export: ts-hello-world.xml (also available inside the semantics-exercises zip).
- Reference docs
- Developer's Guide sections for
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.