Skip to content

Commit

Permalink
repare first steps
Browse files Browse the repository at this point in the history
  • Loading branch information
mpagni12 committed Jan 14, 2025
1 parent 0f4d3f5 commit d4593ae
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion doc/first_steps/fuseki.config.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
] ;
fuseki:endpoint [
fuseki:operation fuseki:gsp-rw ;
fuseki:name "data"
fuseki:name "store"
] ;
fuseki:endpoint [
fuseki:operation fuseki:patch ;
Expand Down
8 changes: 6 additions & 2 deletions doc/first_steps/fuseki.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: kgsteward_yaml_2
server:
brand : fuseki
type : fuseki
location : http://localhost:3030
server_config : fuseki.config.ttl # actually unused
repository : first_steps
file_server_port : 8003
context_base_IRI: http://example.org/context/
file_loader:
type: store_chunks
url_loader:
type: sparql_load
dataset: !include dataset.yaml
validations:
- sparql/validate/*.rq
7 changes: 6 additions & 1 deletion doc/first_steps/graphdb.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
version: kgsteward_yaml_2
server:
brand : graphdb
type : graphdb
location : http://localhost:7200
server_config : graphdb.config.ttl
username : ${GRAPHDB_USERNAME}
password : ${GRAPHDB_PASSWORD}
repository : first_steps
context_base_IRI: http://example.org/context/
file_loader:
type: sparql_load
url_loader:
type: sparql_load
dataset: !include dataset.yaml
validations:
- sparql/validate/*.rq
8 changes: 6 additions & 2 deletions doc/first_steps/rdf4j.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: kgsteward_yaml_2
server:
brand : rdf4j
type : rdf4j
location : http://localhost:8080/rdf4j-server
server_config : rdf4j.config.ttl
repository : kgsteward_demo_rdf4j
file_server_port : 8002
context_base_IRI: http://example.org/context/
file_loader:
type: store_chunks
url_loader:
type: sparql_load
dataset: !include dataset.yaml
validations:
- sparql/validate/*.rq
Expand Down
4 changes: 2 additions & 2 deletions src/kgsteward/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# that might work on a real triplestore (maybe?)

import subprocess
import urllib

# How to dump a context from the command line:
# curl -G --data-urlencode "graph=http://example.org/context/ReconX_schema" http://localhost:7200/repositories/ReconXKG2/rdf-graphs/service
Expand Down Expand Up @@ -121,7 +122,7 @@ def _flush_buf( self, context, data, headers = {}, echo = True ):
http_call(
{
'method' : 'POST',
'url' : self.endpoint_store + "?graph=" + context,
'url' : self.endpoint_store + "?graph=" + urllib.parse.quote_plus( context ),
'headers' : {
**headers,
'Content-Type' : 'text/plain',
Expand All @@ -133,7 +134,6 @@ def _flush_buf( self, context, data, headers = {}, echo = True ):
echo
)


def load_from_file_using_riot( self, file, context, headers = {}, echo = True ):
""" use graph store protocol and riot """
if echo:
Expand Down
14 changes: 7 additions & 7 deletions src/kgsteward/kgsteward.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,16 @@ def main():
}}
}}""" )
if "file" in target :
if config["server"]["file_loader"]["type"] == "http_server":
fs = LocalFileServer( port = config["server"]["file_loader"][ "port" ] )
if config["file_loader"]["type"] == "http_server":
fs = LocalFileServer( port = config["file_loader"][ "port" ] )
for path in target["file"] :
for dir, fn in expand_path( path, config["kgsteward_yaml_directory"] ):
if not os.path.isfile( dir + "/" + fn ):
stop_error( "File not found: " + dir + "/" + fn )
fs.expose( dir ) # cache already exposed directory
if not is_running_in_a_container:
try:
path = "http://localhost:" + str( config["server"]["file_loader"][ "port" ] ) + "/" + fn
path = "http://localhost:" + str( config["file_loader"][ "port" ] ) + "/" + fn
server.sparql_update( f"LOAD <{path}> INTO GRAPH <{context}>" )
except Exception as e:
msg = str( e )
Expand All @@ -451,16 +451,16 @@ def main():
}}
}}""" )
fs.terminate()
else: # config["server"]["file_loader"]["type"] != "http_server"
else: # config["file_loader"]["type"] != "http_server"
for path in target["file"] :
for dir, fn in expand_path( path, config["kgsteward_yaml_directory"] ):
filename = dir + "/" + fn
if config["server"]["file_loader"]["type"] == "sparql_load":
if config["file_loader"]["type"] == "sparql_load":
server.sparql_update( f"LOAD <file://{filename}> INTO GRAPH <{context}>" )
elif config["server"]["file_loader"]["type"] == "chunked_store_file":
elif config["file_loader"]["type"] == "store_chunks":
server.load_from_file_using_riot( filename, context )
else:
raise SystemError( "Unexpected file loader type: " + config["server"]["file_loader"]["type"] )
raise SystemError( "Unexpected file loader type: " + config["file_loader"]["type"] )
server.sparql_update( f"""PREFIX void: <http://rdfs.org/ns/void#>
INSERT DATA {{
GRAPH <{context}> {{
Expand Down
26 changes: 14 additions & 12 deletions src/kgsteward/yamlconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,6 @@ class DatasetConf( BaseModel ):
update : Optional[ list[ str ]] = Field( None, title = "SPARQL update file(s)", description = describe( "update" ))
zenodo : Optional[ list[ int ]] = Field( None, title = "Ignore me", description = describe( "zenodo" ))

class KGStewardConf( BaseModel ):
model_config = ConfigDict( extra='allow' )
version : Literal[ "kgsteward_yaml_2" ] = Field( title = "YAML syntax version", description = "This mandatory fixed value determines the admissible YAML syntax" )
server : Union[ GraphDBConf, RDF4JConf, FusekiConf ]
dataset : list[ DatasetConf ] = Field( title = "Knowledge Graph content", description = describe( "dataset" ))
context_base_IRI : str = Field( title = "context base IRI", description = describe( "context_base_IRI" ) )
queries : Optional[ list[ str ]] = Field( None, title = "GraphDB queries", description = describe( "queries" ))
validations : Optional[ list[ str ]] = Field( None, title = "Validation queries", description = describe( "validations" ))

class DirectFileLoader( BaseModel ):
type : Literal[ "sparql_load" ] = Field( title = "direct file_loader", description = describe( "direct_file_loader" ) )

Expand All @@ -171,17 +162,28 @@ class HttpServerFileLoader( BaseModel ):
port : Optional[ int ] = Field( 8000, title = "file_server_port", description = describe( "file_server_port" ))

class ChunkedStoreFileLoader( BaseModel ):
type : Literal[ "chunked_store" ] = Field( title = "HTTP file server", description = "http_file_server" )
port : Optional[ int ] = Field( 1e8, title = "chunked_store", description = "chunked_store_file" )
type : Literal[ "store_chunks" ] = Field( title = "HTTP file server", description = "http_file_server" )
size : Optional[ int ] = Field( 100_000_000, title = "chunked_store", description = "chunked_store_file" )

class DirectUrlLoader( BaseModel ):
type : Literal[ "load_url" ] = Field( title = "direct url loader", description = describe( "direct_url_loader" ))
type : Literal[ "sparql_load" ] = Field( title = "direct url loader", description = describe( "direct_url_loader" ))

class CurlChunkedStoreUrlLoader( BaseModel ):
type : Literal[ "curl_chunked_store_url_loader" ] = Field( title = "direct url loader", description = "direct_url_loader" )
tmp_dir : Optional[ str ] = Field( "/tmp", title = "temporary directory", description = "temporary directory" )
port : Optional[ int ] = Field( 1e8, title = "chunked_store", description = "chunked_store_file")

class KGStewardConf( BaseModel ):
model_config = ConfigDict( extra='allow' )
version : Literal[ "kgsteward_yaml_2" ] = Field( title = "YAML syntax version", description = "This mandatory fixed value determines the admissible YAML syntax" )
server : Union[ GraphDBConf, RDF4JConf, FusekiConf ]
file_loader : Union[ DirectFileLoader, HttpServerFileLoader, ChunkedStoreFileLoader ]
url_loader : Union[ DirectUrlLoader ]
dataset : list[ DatasetConf ] = Field( title = "Knowledge Graph content", description = describe( "dataset" ))
context_base_IRI : str = Field( title = "context base IRI", description = describe( "context_base_IRI" ) )
queries : Optional[ list[ str ]] = Field( None, title = "GraphDB queries", description = describe( "queries" ))
validations : Optional[ list[ str ]] = Field( None, title = "Validation queries", description = describe( "validations" ))

def parse_yaml_conf( path : str ):
"""Parsing kgsteward YAML config file(s) is a three step process:
1. Parse YAML file(s) and execute !include directive
Expand Down

0 comments on commit d4593ae

Please sign in to comment.