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
82f240eb
Commit
82f240eb
authored
3 years ago
by
Valerian Wintner
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup fetching/writing.
parent
ad4be187
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/kgshape/app/Query.java
+19
-14
19 additions, 14 deletions
src/main/java/com/kgshape/app/Query.java
with
19 additions
and
14 deletions
src/main/java/com/kgshape/app/Query.java
+
19
−
14
View file @
82f240eb
...
@@ -13,12 +13,13 @@ import org.apache.logging.log4j.core.config.DefaultConfiguration;
...
@@ -13,12 +13,13 @@ import org.apache.logging.log4j.core.config.DefaultConfiguration;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.FileSystemNotFoundException
;
/**
/**
*
See: https://jena.apache.org/documentation/query/app_api.html
*
Queries a remote endpoint.
*/
*/
public
class
Query
{
public
class
Query
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
// https://stackoverflow.com/questions/41442024/basicconfigurator-replacement-in-log4j2
// https://stackoverflow.com/questions/41442024/basicconfigurator-replacement-in-log4j2
Configurator
.
initialize
(
new
DefaultConfiguration
());
Configurator
.
initialize
(
new
DefaultConfiguration
());
Configurator
.
setRootLevel
(
Level
.
INFO
);
Configurator
.
setRootLevel
(
Level
.
INFO
);
...
@@ -45,23 +46,27 @@ public class Query {
...
@@ -45,23 +46,27 @@ public class Query {
// You can also open this endpoint in the browser and test the above query
// You can also open this endpoint in the browser and test the above query
String
endpoint
=
"https://dbpedia.org/sparql"
;
String
endpoint
=
"https://dbpedia.org/sparql"
;
Model
fetchedModel
=
fetchConstruct
(
endpoint
,
construct_query
);
writeModel
(
fetchedModel
,
"rdf_file.ttl"
);
}
public
static
Model
fetchConstruct
(
String
endpoint
,
String
query
)
{
// https://jena.apache.org/documentation/query/sparql-remote.html
// https://jena.apache.org/documentation/query/sparql-remote.html
QueryExecution
qexec
=
QueryExecutionFactory
.
sparqlService
(
endpoint
,
construct_query
);
// Also see: https://jena.apache.org/documentation/query/app_api.html
QueryExecution
qexec
=
QueryExecutionFactory
.
sparqlService
(
endpoint
,
query
);
Model
resultModel
=
qexec
.
execConstruct
();
Model
resultModel
=
qexec
.
execConstruct
();
qexec
.
close
();
return
resultModel
;
}
// RDFDataMgr.write(System.out, resultModel, Lang.TURTLE);
public
static
void
writeModel
(
Model
model
,
String
filename
)
throws
FileSystemNotFoundException
,
IOException
{
// RDFDataMgr.write(System.out, resultModel, Lang.TURTLE); // Write it to stdout
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
"rdf.ttl"
))
{
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
filename
))
{
// See: https://jena.apache.org/documentation/io/rdf-output.html#opt-turtle-trig
// See: https://jena.apache.org/documentation/io/rdf-output.html#opt-turtle-trig
RDFDataMgr
.
write
(
fos
,
resultModel
,
Lang
.
TURTLE
);
RDFDataMgr
.
write
(
fos
,
model
,
Lang
.
TURTLE
);
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
qexec
.
close
();
System
.
out
.
println
(
"Hello 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