Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oxibug
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
captnfab
Oxibug
Commits
d383cc79
Commit
d383cc79
authored
1 month ago
by
Fabien Givors
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
Cargo.toml
+8
-0
8 additions, 0 deletions
Cargo.toml
src/main.rs
+88
-0
88 additions, 0 deletions
src/main.rs
with
97 additions
and
0 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
d383cc79
/target
This diff is collapsed.
Click to expand it.
Cargo.toml
0 → 100644
+
8
−
0
View file @
d383cc79
[package]
name
=
"oxibug"
version
=
"0.1.0"
edition
=
"2024"
[dependencies]
oxigraph
=
"0.4.8"
reqwest
=
{
version
=
"0.12.12"
,
features
=[
"blocking"
]
}
This diff is collapsed.
Click to expand it.
src/main.rs
0 → 100644
+
88
−
0
View file @
d383cc79
use
oxigraph
::
store
::
Store
;
fn
download_shacl
()
->
Vec
<
u8
>
{
use
reqwest
::
blocking
::
Client
;
let
client
=
Client
::
new
();
let
shacl_url
=
"https://www.w3.org/ns/shacl.ttl"
;
client
.get
(
shacl_url
)
.send
()
.expect
(
"failed to download file"
)
.bytes
()
.expect
(
"failed to build bytes"
)
.to_vec
()
}
fn
load_turtle
(
store
:
&
mut
Store
,
bytes
:
&
[
u8
])
{
use
oxigraph
::
io
::{
RdfFormat
,
RdfParser
};
use
oxigraph
::
model
::{
GraphNameRef
,
NamedNodeRef
};
let
shacl_ns
=
"http://www.w3.org/ns/shacl"
;
let
graph_iri
=
GraphNameRef
::
NamedNode
(
NamedNodeRef
::
new_unchecked
(
shacl_ns
));
store
.bulk_loader
()
.load_from_reader
(
RdfParser
::
from_format
(
RdfFormat
::
Turtle
)
.without_named_graphs
()
.with_default_graph
(
graph_iri
),
bytes
,
)
.expect
(
"unable to load data"
)
}
fn
perform_query_1
(
store
:
&
Store
)
{
use
oxigraph
::
sparql
::
QueryResults
;
let
query_str
=
"
SELECT DISTINCT
?node
?label
?inverse_label
?type
WHERE {
GRAPH <http://www.w3.org/ns/shacl> {
?node ?p ?o .
}
GRAPH <http://www.w3.org/ns/shacl> {
#OPTIONAL { ?node <http://www.w3.org/2000/01/rdf-schema#label> ?label . } .
OPTIONAL { ?node <http://example.com/ns#inverseLabel> ?inverse_label . } .
} .
GRAPH <http://www.w3.org/ns/shacl> {
OPTIONAL { ?node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type . } .
}
FILTER(?node = <http://www.w3.org/ns/shacl#ClosedConstraintComponent-closed>)
}
"
;
if
let
QueryResults
::
Solutions
(
solutions
)
=
store
.query
(
query_str
)
.expect
(
"invalid query"
)
{
println!
(
"Query 1: {}"
,
solutions
.count
());
}
}
fn
perform_query_2
(
store
:
&
Store
)
{
use
oxigraph
::
sparql
::
QueryResults
;
let
query_str
=
"
SELECT DISTINCT
?node
?label
?inverse_label
?type
WHERE {
GRAPH <http://www.w3.org/ns/shacl> {
?node ?p ?o .
}
GRAPH <http://www.w3.org/ns/shacl> {
OPTIONAL { ?node <http://www.w3.org/2000/01/rdf-schema#label> ?label . } .
OPTIONAL { ?node <http://example.com/ns#inverseLabel> ?inverse_label . } .
} .
GRAPH <http://www.w3.org/ns/shacl> {
OPTIONAL { ?node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type . } .
}
FILTER(?node = <http://www.w3.org/ns/shacl#ClosedConstraintComponent-closed>)
}
"
;
if
let
QueryResults
::
Solutions
(
solutions
)
=
store
.query
(
query_str
)
.expect
(
"invalid query"
)
{
println!
(
"Query 2: {}"
,
solutions
.count
());
}
}
fn
main
()
{
let
mut
store
=
Store
::
new
()
.expect
(
"failed to create new store"
);
let
shacl_bytes
=
download_shacl
();
load_turtle
(
&
mut
store
,
&
shacl_bytes
);
perform_query_1
(
&
store
);
perform_query_2
(
&
store
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment