Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
KG Shapes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Danielle Maree McKenney
KG Shapes
Commits
9dde8ddb
Commit
9dde8ddb
authored
3 years ago
by
Valerian Wintner
Committed by
Gritsch Philipp - Studierendenaccount
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Query: Option to only get properties belonging to this class, to the superclass, or everything.
parent
640e9e55
No related branches found
Branches containing commit
No related tags found
1 merge request
!5
Fixes RDF2Graph further.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
framework/src/main/java/com/kgshape/app/Query.java
+94
-15
94 additions, 15 deletions
framework/src/main/java/com/kgshape/app/Query.java
with
94 additions
and
15 deletions
framework/src/main/java/com/kgshape/app/Query.java
+
94
−
15
View file @
9dde8ddb
package
com.kgshape.app
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.file.FileSystemNotFoundException
;
import
org.apache.jena.query.QueryExecution
;
import
org.apache.jena.query.QueryExecutionFactory
;
import
org.apache.jena.rdf.model.Model
;
import
org.apache.jena.riot.Lang
;
import
org.apache.jena.riot.RDFDataMgr
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.file.FileSystemNotFoundException
;
/**
* Queries a remote endpoint.
*/
...
...
@@ -22,20 +22,81 @@ public class Query {
PREFIX o: <http://dbpedia.org/ontology/>
select distinct ?subj where {?subj a o:Language} LIMIT 20
"""
;
// Get 100 different actors
String
construct_
query
=
"""
String
format_
construct_
all
=
"""
PREFIX o: <http://dbpedia.org/ontology/>
CONSTRUCT {?person ?pred ?obj}
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?subj ?pred ?obj.
}
WHERE {
?
person
?pred ?obj
{
SELECT DISTINCT(?
person
)
WHERE {
?person a o:Actor
} LIMIT 100
}
?
subj
?pred ?obj
.
{
SELECT DISTINCT(?
subj
)
WHERE {
?subj a o:%1$s
} LIMIT 100
}
}
"""
;
String
format_construct
=
"""
PREFIX o: <http://dbpedia.org/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?subj ?pred ?obj.
?subj a o:%1$s.
}
WHERE {
?subj ?pred ?obj.
{
SELECT DISTINCT(?subj)
WHERE {
?subj a o:%1$s
} LIMIT 100
}
{
SELECT DISTINCT ?pred WHERE {
?pred rdfs:domain o:%1$s.
}
}
}
"""
;
String
format_construct_super
=
"""
PREFIX o: <http://dbpedia.org/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?subj ?pred ?obj.
?subj a ?class.
}
WHERE {
?subj ?pred ?obj.
?subj a ?class.
{
SELECT DISTINCT(?subj)
WHERE {
?subj a o:%1$s
} LIMIT 100
}
{
SELECT DISTINCT ?pred WHERE {
{
?pred rdfs:domain ?class.
}
}
}
{
SELECT ?class WHERE {
o:%1$s rdfs:subClassOf* ?class.
}
}
}
"""
;
// System.out.println(construct_query);
String
construct_query2
=
"""
PREFIX o: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
...
...
@@ -47,8 +108,26 @@ public class Query {
// You can also open this endpoint in the browser and test the above query
String
endpoint
=
"https://dbpedia.org/sparql"
;
// Pick the name of the class we want to extract from the arguments
String
className
;
if
(
args
.
length
<
1
)
{
className
=
"Artist"
;
}
else
{
className
=
args
[
0
];
}
String
construct_query
=
String
.
format
(
format_construct
,
className
);
Model
fetchedModel
=
fetchConstruct
(
endpoint
,
construct_query
);
writeModel
(
fetchedModel
,
"rdf_file.ttl"
);
writeModel
(
fetchedModel
,
"rdf_"
+
className
+
".ttl"
);
String
construct_query_super
=
String
.
format
(
format_construct_super
,
className
);
fetchedModel
=
fetchConstruct
(
endpoint
,
construct_query_super
);
writeModel
(
fetchedModel
,
"rdf_"
+
className
+
"_super.ttl"
);
String
construct_query_all
=
String
.
format
(
format_construct_all
,
className
);
fetchedModel
=
fetchConstruct
(
endpoint
,
construct_query_all
);
writeModel
(
fetchedModel
,
"rdf_"
+
className
+
"_all.ttl"
);
}
public
static
Model
fetchConstruct
(
String
endpoint
,
String
query
)
{
...
...
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