简体   繁体   中英

Accessing linked data graphs using SPARQL

I am using OpenLink Virtuoso to convert a Relational Database to RDF using this tutorial .

I have a database with 5 tables ( Authors , Keywords , Publications , References , Rights ), and I imported them in Virtuoso database using .csv files.

In the end of the "conversion" from RDB to Linked-Data graphs it presents the status of the operations which turn out OK, and gives me the following links:

SQL Relations (Tables) to RDF Statements (Predicate / Property Graph) Mappings

http://localhost:8890/schemas/CSV/qm-authors_csv
http://localhost:8890/schemas/CSV/qm-keywords_csv
http://localhost:8890/schemas/CSV/qm-publications_csv
http://localhost:8890/schemas/CSV/qm-references_csv
http://localhost:8890/schemas/CSV/qm-rights_csv
http://localhost:8890/schemas/CSV/qm-VoidStatistics

Sample Graph IRIs & Linked Data Entity URIs

RDFDocument (Named Graph) IRIs:

Transient Views: http://localhost:8890/CSV#
http://localhost:8890/CSV/authors_csv/ID/1#this
http://localhost:8890/CSV/authors_csv/ID/1#this
http://localhost:8890/CSV/keywords_csv/ID/1#this
http://localhost:8890/CSV/publications_csv/ID/1#this
http://localhost:8890/CSV/publications_csv/ID/1#this
http://localhost:8890/CSV/objects/publications_csv/ID/1/DisplayOnMLKD.bin
http://localhost:8890/CSV/references_csv/ID/1#this
http://localhost:8890/CSV/references_csv/ID/1#this
http://localhost:8890/CSV/rights_csv/ID/1#this
http://localhost:8890/CSV/rights_csv/ID/1#this
Metadata Data Document (VoiD) URI/URL: http://localhost:8890/CSV/stat#
Linked Data Ontology URI: http://localhost:8890/schemas/CSV/

I tried using the following SPARQL query to view all the results to check them:

SELECT *
FROM <http://localhost:8890/CSV>
WHERE {?s ?o ?p}

But what I need is to check each graph separately.

Question 1:

Based on the above results how can I access each of the graphs (for the tables Authors , Publications , References etc.) that were created using SPARQL?

Question 2:

What query should I write to delete a graph?

I recommend that you take at least a cursory look through SPARQL 1.1 Query Language and SPARQL 1.1 Update . You don't need to memorize every aspect of them, but skimming over the table of contents will give you an idea of what's in the language, and you'll have an idea where to look in the future. (In my opinion, this is good advice for any toolkit, language, etc., that you might learn or use.)

Querying in one or more graphs

Have a look at 13.3 Querying the Dataset and its subsections where you'll find examples of how to query different graphs. In short, you use a pattern like

select ... where {
  ...
  graph ?g { ... }
  ...
}

By default, ?g will range over all the graphs in your dataset. If you use some from named parts in your query, then you can restrict what it will range over. You can also specify a graph IRI directly, as in

graph <http://example.org/graph-to-check> { ... }

There are more examples in the spec, of course.

 SELECT * FROM <http://localhost:8890/CSV> WHERE {?s ?o ?p}

But what I need is to check each graph seperately.

You can use a query like

select * where { graph ?g { ?s ?p ?o } }

to get each triple and the graph that it occurs in. Note that (like RobV did in an answer to one of your earlier questions ), I've changed the variable names because triples are (subject,predicate,object), so ?s ?p ?o makes more mnemonic sense than ?s ?o ?p .

Deleting a graph

The 3.2 Graph Management section describes the five operations that you can use to manipulate graphs (emphasis added):

  • The CREATE operation creates a new graph in stores that support empty graphs.
  • The DROP operation removes a graph and all of its contents.
  • The COPY operation modifies a graph to contain a copy of another.
  • The MOVE operation moves all of the data from one graph into another.
  • The ADD operation reproduces all data from one graph into another.

The given syntax is

DROP  ( SILENT )? (GRAPH IRIref | DEFAULT | NAMED | ALL )

so you'd just do, eg,

drop graph <http://example.org/graph-to-delete>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM