diff --git a/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java b/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java index bf1b1d8d7..27a72767f 100644 --- a/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java +++ b/src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java @@ -7,7 +7,6 @@ import arq.cmdline.ModTime; import org.apache.jena.cmd.ArgDecl; -import org.apache.jena.graph.NodeFactory; import org.apache.jena.query.Query; import org.apache.jena.query.ResultSet; import org.apache.jena.sparql.core.Var; @@ -16,6 +15,7 @@ import org.apache.jena.sparql.syntax.ElementPathBlock; import org.apache.jena.sparql.util.QueryExecUtils; +import se.liu.ida.hefquin.cli.modules.ModLPG2RDFConfiguration; import se.liu.ida.hefquin.cli.modules.ModQuery; import se.liu.ida.hefquin.engine.data.SolutionMapping; import se.liu.ida.hefquin.engine.data.VocabularyMapping; @@ -34,17 +34,8 @@ import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.LPG2RDFConfiguration; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.Record2SolutionMappingTranslator; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.SPARQLStar2CypherTranslator; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationImpl; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.Record2SolutionMappingTranslatorImpl; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.SPARQLStar2CypherTranslatorImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.NodeLabelMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.EdgeLabelMappingToURIsImpl; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMapping; -import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.PropertyNameMappingToURIsImpl; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.query.CypherMatchQuery; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.query.CypherQuery; import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.query.CypherUnionQuery; @@ -58,6 +49,7 @@ public class RunBGPOverNeo4j extends CmdARQ protected final ModTime modTime = new ModTime(); protected final ModQuery modQuery = new ModQuery(); protected final ModResultsOut modResults = new ModResultsOut(); + protected final ModLPG2RDFConfiguration modLPG2RDFConfiguration = new ModLPG2RDFConfiguration(); protected final ArgDecl argEndpointURI = new ArgDecl(ArgDecl.HasValue, "endpoint"); protected final ArgDecl argNaive = new ArgDecl(ArgDecl.NoValue, "naive"); @@ -65,13 +57,6 @@ public class RunBGPOverNeo4j extends CmdARQ protected final ArgDecl argNoMerge = new ArgDecl(ArgDecl.NoValue, "disablePathMerging"); protected final ArgDecl argSuppressResultPrintout = new ArgDecl(ArgDecl.NoValue, "suppressResultPrintout"); - protected static final String LABEL = "http://www.w3.org/2000/01/rdf-schema#label"; - - protected static final String NSNODE = "https://example.org/node/"; - protected static final String NSNODELABEL = "https://example.org/label/"; - protected static final String NSRELATIONSHIP = "https://example.org/relationship/"; - protected static final String NSPROPERTY = "https://example.org/property/"; - public static void main( final String[] args ) { new RunBGPOverNeo4j(args).mainRun(); } @@ -84,6 +69,7 @@ protected RunBGPOverNeo4j( final String[] argv ) { add(argSuppressResultPrintout, "--suppressResultPrintout", "Do not print out the query result"); + addModule(modLPG2RDFConfiguration); addModule(modQuery); add(argEndpointURI, "--endpoint", "The URI of the Neo4j endpoint"); @@ -102,11 +88,7 @@ protected String getSummary() { protected void exec() { final BGP bgp = getBGP(); - final NodeMapping nodeMapping = new NodeMappingToURIsImpl(NSNODE); - final NodeLabelMapping nodeLabelMapping = new NodeLabelMappingToURIsImpl(NSNODELABEL); - final EdgeLabelMapping edgeLabelMapping = new EdgeLabelMappingToURIsImpl(NSRELATIONSHIP); - final PropertyNameMapping propertyNameMapping = new PropertyNameMappingToURIsImpl(NSPROPERTY); - final LPG2RDFConfiguration conf = new LPG2RDFConfigurationImpl(NodeFactory.createURI(LABEL), nodeMapping, nodeLabelMapping,edgeLabelMapping,propertyNameMapping); + final LPG2RDFConfiguration conf = modLPG2RDFConfiguration.getLPG2RDFConfigurationCatalog(); final Pair> tRes = performQueryTranslation(bgp, conf); diff --git a/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java new file mode 100644 index 000000000..368954725 --- /dev/null +++ b/src/main/java/se/liu/ida/hefquin/cli/modules/ModLPG2RDFConfiguration.java @@ -0,0 +1,47 @@ +package se.liu.ida.hefquin.cli.modules; + +import org.apache.jena.cmd.ArgDecl; +import org.apache.jena.cmd.CmdArgModule; +import org.apache.jena.cmd.CmdGeneral; +import org.apache.jena.cmd.ModBase; +import org.apache.jena.graph.NodeFactory; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.LPG2RDFConfiguration; +import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.*; + +public class ModLPG2RDFConfiguration extends ModBase { + protected final ArgDecl lpg2RDFDescrDecl = new ArgDecl(ArgDecl.HasValue, "lpg2rdfconf", "lpg2rdf", "LPG2RDFConfigurationDescription"); + protected static final String NSNODE = "https://example.org/node/"; + protected static final String NSRELATIONSHIP = "https://example.org/relationship/"; + protected static final String NSPROPERTY = "https://example.org/property/"; + protected static final String LABEL = "http://www.w3.org/2000/01/rdf-schema#label"; + + + protected LPG2RDFConfiguration cat = null; + + @Override + public void registerWith( final CmdGeneral cmdLine ) { + cmdLine.getUsage().startCategory("LPG to RDF Mapping"); + cmdLine.add(lpg2RDFDescrDecl, "--lpg2rdfconf", "file with an RDF description of the LPG-to-RDF configuration"); + } + + @Override + public void processArgs( final CmdArgModule cmdLine ) { + if ( cmdLine.contains(lpg2RDFDescrDecl) ) { + final String lpg2RDFDescrFilename = cmdLine.getValue(lpg2RDFDescrDecl); + cat = LPG2RDFConfigurationReader.readFromFile(lpg2RDFDescrFilename); + } + else{ + final NodeMapping nodeMapping = new NodeMappingToURIsImpl(NSNODE); + final NodeLabelMapping nodeLabelMapping = new NodeLabelMappingToLiteralsImpl(); + final EdgeLabelMapping edgeLabelMapping = new EdgeLabelMappingToURIsImpl(NSRELATIONSHIP); + final PropertyNameMapping propertyNameMapping = new PropertyNameMappingToURIsImpl(NSPROPERTY); + cat = new LPG2RDFConfigurationImpl(NodeFactory.createURI(LABEL), nodeMapping, nodeLabelMapping,edgeLabelMapping,propertyNameMapping); + } + } + + + public LPG2RDFConfiguration getLPG2RDFConfigurationCatalog() { + return cat; + } + +}