test_graph v0.1.0 TestGraph
Top-level module used in "Graph to graph with Elixir" post.
This post explores moving data between semantic and property graphs.
See the examples directory for some example scripts.
Here's an example of querying a remote RDF service (DBpedia)
using the SPARQL.Client
module via a wrapped function SPARQL_Client.rquery!/1
and using the stored procedures in the NeoSemantics
module for transforming
the semantic graph to a property graph and importing into a Neo4j
instance.
This example saves the RDF graph for staging. (Not known yet how to deal
with in-memory graphs using the neosemantics
library.)
Examples
# 1. explicit form
iex> elixir = (
...> TestGraph.RDF.read_query("elixir.rq").data
...> |> TestGraph.RDF.SPARQL.Client.rquery!
...> |> RDF.Turtle.write_string!
...> |> TestGraph.RDF.write_graph("elixir.ttl")
...> )
iex> conn() |> NeoSemantics.import_rdf!(elixir.uri, "Turtle")
# 2. implicit form
iex> TestGraph.import_rdf_from_query("elixir.rq")
# 3. implicit form (with alias)
iex> import_rdf_from_query("elixir.rq")
Link to this section Summary
Functions
Delegates to TestGraph.LPG.Cypher.Client.rquery/0
Delegates to TestGraph.LPG.Cypher.Client.rquery/1
Delegates to TestGraph.LPG.Cypher.Client.rquery/0
Delegates to TestGraph.LPG.Cypher.Client.rquery/1
Delegates to TestGraph.LPG.Cypher.Client.clear/0
Delegates to TestGraph.LPG.Cypher.Client.dump/1
Delegates to TestGraph.LPG.Cypher.Client.dump/2
Delegates to TestGraph.LPG.Cypher.Client.init/0
Delegates to TestGraph.LPG.Cypher.Client.reset/0
Delegates to TestGraph.LPG.Cypher.Client.test/0
Delegates to TestGraph.RDF.SPARQL.Client.dbpedia_sparql_endpoint/0
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is centered on a node identified by node_id
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is defined by the cypher
query
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is defined by the cypher
query
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is centered on a node identified by node_uri
Imports into Neo4j an LPG graph transformed from an RDF graph
Imports into Neo4j an LPG graph transformed from an RDF graph which was queried from a remote datastore using a SPARQL endpoint
Delegates to TestGraph.LPG.list_graphs/0
Delegates to TestGraph.LPG.list_queries/0
Delegates to TestGraph.RDF.list_graphs/0
Delegates to TestGraph.RDF.list_queries/0
Delegates to TestGraph.RDF.SPARQL.Client.sparql_services/0
Delegates to TestGraph.RDF.SPARQL.Client.local_sparql_endpoint/0
Delegates to TestGraph.LPG.books/0
Delegates to TestGraph.LPG.movies/0
Delegates to TestGraph.RDF.books/0
Delegates to TestGraph.LPG.read_graph/0
Delegates to TestGraph.LPG.read_graph/1
Delegates to TestGraph.LPG.read_query/0
Delegates to TestGraph.LPG.read_query/1
Delegates to TestGraph.RDF.read_graph/0
Delegates to TestGraph.RDF.read_graph/1
Delegates to TestGraph.RDF.read_query/0
Delegates to TestGraph.RDF.read_query/1
Delegates to TestGraph.RDF.SPARQL.Client.rquery/0
Delegates to TestGraph.RDF.SPARQL.Client.rquery/1
Delegates to TestGraph.RDF.SPARQL.Client.rquery/2
Delegates to TestGraph.RDF.SPARQL.Client.rquery/0
Delegates to TestGraph.RDF.SPARQL.Client.rquery/1
Delegates to TestGraph.RDF.SPARQL.Client.rquery/2
Delegates to TestGraph.RDF.SPARQL.Client.sparql_endpoint/0
Delegates to TestGraph.RDF.SPARQL.Client.sparql_endpoint/1
Delegates to TestGraph.RDF.SPARQL.Client.sparql_query/0
Delegates to TestGraph.RDF.SPARQL.Client.sparql_query/1
Delegates to TestGraph.RDF.SPARQL.Client.wikidata_sparql_endpoint/0
Delegates to TestGraph.LPG.write_graph/1
Delegates to TestGraph.LPG.write_graph/2
Delegates to TestGraph.LPG.write_query/1
Delegates to TestGraph.LPG.write_query/2
Delegates to TestGraph.RDF.write_graph/1
Delegates to TestGraph.RDF.write_graph/2
Delegates to TestGraph.RDF.write_query/1
Delegates to TestGraph.RDF.write_query/2
Link to this section Functions
cypher()
Delegates to TestGraph.LPG.Cypher.Client.rquery/0
cypher(arg)
Delegates to TestGraph.LPG.Cypher.Client.rquery/1
cypher!()
Delegates to TestGraph.LPG.Cypher.Client.rquery/0
cypher!(arg)
Delegates to TestGraph.LPG.Cypher.Client.rquery/1
cypher_clear()
Delegates to TestGraph.LPG.Cypher.Client.clear/0
cypher_dump(arg)
Delegates to TestGraph.LPG.Cypher.Client.dump/1
cypher_dump(arg1, arg2)
Delegates to TestGraph.LPG.Cypher.Client.dump/2
cypher_init()
Delegates to TestGraph.LPG.Cypher.Client.init/0
cypher_reset()
Delegates to TestGraph.LPG.Cypher.Client.reset/0
cypher_test()
Delegates to TestGraph.LPG.Cypher.Client.test/0
dbpedia_sparql_endpoint()
Delegates to TestGraph.RDF.SPARQL.Client.dbpedia_sparql_endpoint/0
export_rdf_by_id(node_id, exclude_context \\ false)
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is centered on a node identified by node_id
.
This returns the full context unless an optional boolean arg exclude_context
is passed as true
which will exclude context if present.
Examples
iex> TestGraph.export_rdf_by_id(1783)
%TestGraph.Graph{
data: "@prefix neovoc: <neo4j://defaultvocabulary#> .\n@prefix neoind: <neo4j://indiv#> .\n\n\nneoind:1783 a neovoc:Resource;\n neovoc:ns0__creator neoind:1785;\n neovoc:ns0__homepage neoind:1784;\n neovoc:ns0__license neoind:1786;\n neovoc:ns0__name "Elixir";\n neovoc:uri "http://example.org/Elixir" .\n",
file: "1783.ttl",
path: "/Users/tony/Projects/github/tonyhammond/ex_mples/test_graph/_build/dev/lib/test_graph/priv/rdf/graphs/1783.ttl",
type: :rdf,
uri: "file:///Users/tony/Projects/github/tonyhammond/ex_mples/test_graph/_build/dev/lib/test_graph/priv/rdf/graphs/1783.ttl"
}
iex> TestGraph.export_rdf_by_id(1783).data
"@prefix neovoc: <neo4j://defaultvocabulary#> .\n@prefix neoind: <neo4j://indiv#> .\n\n\nneoind:1783 a neovoc:Resource;\n neovoc:ns0__creator neoind:1785;\n neovoc:ns0__homepage neoind:1784;\n neovoc:ns0__license neoind:1786;\n neovoc:ns0__name "Elixir";\n neovoc:uri "http://example.org/Elixir" .\n"
export_rdf_by_query(cypher, graph_file)
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is defined by the cypher
query.
Examples
iex> cypher = TestGraph.LPG.read_query("node1.cypher").data
"match (n) return n limit 1\n"
iex> cypher |> TestGraph.export_rdf_by_query
export_rdf_by_query_on_rdf(cypher, graph_file)
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is defined by the cypher
query.
Examples
iex> cypher =
"match (n:Resource {uri:'http://dataset/indiv#153'}) return n\n"
iex> cypher |> TestGraph.export_rdf_by_query_on_rdf
export_rdf_by_uri(node_uri, exclude_context \\ false)
Exports from Neo4j an LPG graph transformed into an RDF graph. The graph
is centered on a node identified by node_uri
.
This returns the full context unless an optional boolean arg exclude_context
is passed as true
which will exclude context if present.
Examples
iex> TestGraph.export_rdf_by_uri("http://example.org/Elixir")
%TestGraph.Graph{
data: "@prefix neovoc: <neo4j://vocabulary#> .\n\n\n<http://example.org/Elixir> <http://example.org/creator> <http://dbpedia.org/resource/José_Valim>;\n <http://example.org/homepage> <http://elixir-lang.org>;\n <http://example.org/license> <http://dbpedia.org/resource/Apache_License>;\n <http://example.org/name> "Elixir" .\n",
file: "http___example.org_Elixir.ttl",
path: ... <> "/test_graph/priv/rdf/graphs/http___example.org_Elixir.ttl",
type: :rdf,
uri: "file:///" <> ... <> "/test_graph/priv/rdf/graphs/http___example.org_Elixir.ttl"
}
iex> TestGraph.export_rdf_by_uri("http://example.org/Elixir").data
"@prefix neovoc: <neo4j://vocabulary#> .\n\n\n<http://example.org/Elixir> <http://example.org/creator> <http://dbpedia.org/resource/José_Valim>;\n <http://example.org/homepage> <http://elixir-lang.org>;\n <http://example.org/license> <http://dbpedia.org/resource/Apache_License>;\n <http://example.org/name> "Elixir" .\n"
import_rdf_from_graph(graph_file \\ "default.ttl")
Imports into Neo4j an LPG graph transformed from an RDF graph.
Examples
iex> TestGraph.import_rdf_from_graph("elixir.ttl")
[
%{
"extraInfo" => "",
"namespaces" => %{
"http://example.org/" => "ns0",
"http://purl.org/dc/elements/1.1/" => "dc",
"http://purl.org/dc/terms/" => "dct",
"http://schema.org/" => "sch",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#" => "rdf",
"http://www.w3.org/2000/01/rdf-schema#" => "rdfs",
"http://www.w3.org/2002/07/owl#" => "owl",
"http://www.w3.org/2004/02/skos/core#" => "skos"
},
"terminationStatus" => "OK",
"triplesLoaded" => 4
}
]
import_rdf_from_query(query_file \\ "default.rq")
Imports into Neo4j an LPG graph transformed from an RDF graph which was queried from a remote datastore using a SPARQL endpoint.
Examples
iex> TestGraph.import_rdf_from_query("elixir.rq")
[
%{
"extraInfo" => "",
"namespaces" => %{
"http://example.org/" => "ns0",
"http://purl.org/dc/elements/1.1/" => "dc",
"http://purl.org/dc/terms/" => "dct",
"http://schema.org/" => "sch",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#" => "rdf",
"http://www.w3.org/2000/01/rdf-schema#" => "rdfs",
"http://www.w3.org/2002/07/owl#" => "owl",
"http://www.w3.org/2004/02/skos/core#" => "skos"
},
"terminationStatus" => "OK",
"triplesLoaded" => 4
}
]
list_lpg_graphs()
Delegates to TestGraph.LPG.list_graphs/0
list_lpg_queries()
Delegates to TestGraph.LPG.list_queries/0
list_rdf_graphs()
Delegates to TestGraph.RDF.list_graphs/0
list_rdf_queries()
Delegates to TestGraph.RDF.list_queries/0
list_sparql_services()
Delegates to TestGraph.RDF.SPARQL.Client.sparql_services/0
local_sparql_endpoint()
Delegates to TestGraph.RDF.SPARQL.Client.local_sparql_endpoint/0
lpg_books()
Delegates to TestGraph.LPG.books/0
lpg_movies()
Delegates to TestGraph.LPG.movies/0
rdf_books()
Delegates to TestGraph.RDF.books/0
read_lpg_graph()
Delegates to TestGraph.LPG.read_graph/0
read_lpg_graph(arg)
Delegates to TestGraph.LPG.read_graph/1
read_lpg_query()
Delegates to TestGraph.LPG.read_query/0
read_lpg_query(arg)
Delegates to TestGraph.LPG.read_query/1
read_rdf_graph()
Delegates to TestGraph.RDF.read_graph/0
read_rdf_graph(arg)
Delegates to TestGraph.RDF.read_graph/1
read_rdf_query()
Delegates to TestGraph.RDF.read_query/0
read_rdf_query(arg)
Delegates to TestGraph.RDF.read_query/1
sparql()
Delegates to TestGraph.RDF.SPARQL.Client.rquery/0
sparql(arg)
Delegates to TestGraph.RDF.SPARQL.Client.rquery/1
sparql(arg1, arg2)
Delegates to TestGraph.RDF.SPARQL.Client.rquery/2
sparql!()
Delegates to TestGraph.RDF.SPARQL.Client.rquery/0
sparql!(arg)
Delegates to TestGraph.RDF.SPARQL.Client.rquery/1
sparql!(arg1, arg2)
Delegates to TestGraph.RDF.SPARQL.Client.rquery/2
sparql_endpoint()
Delegates to TestGraph.RDF.SPARQL.Client.sparql_endpoint/0
sparql_endpoint(arg)
Delegates to TestGraph.RDF.SPARQL.Client.sparql_endpoint/1
sparql_query()
Delegates to TestGraph.RDF.SPARQL.Client.sparql_query/0
sparql_query(arg)
Delegates to TestGraph.RDF.SPARQL.Client.sparql_query/1
wikidata_sparql_endpoint()
Delegates to TestGraph.RDF.SPARQL.Client.wikidata_sparql_endpoint/0
write_lpg_graph(arg)
Delegates to TestGraph.LPG.write_graph/1
write_lpg_graph(arg1, arg2)
Delegates to TestGraph.LPG.write_graph/2
write_lpg_query(arg)
Delegates to TestGraph.LPG.write_query/1
write_lpg_query(arg1, arg2)
Delegates to TestGraph.LPG.write_query/2
write_rdf_graph(arg)
Delegates to TestGraph.RDF.write_graph/1
write_rdf_graph(arg1, arg2)
Delegates to TestGraph.RDF.write_graph/2
write_rdf_query(arg)
Delegates to TestGraph.RDF.write_query/1
write_rdf_query(arg1, arg2)
Delegates to TestGraph.RDF.write_query/2