Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LPG2RDFConfiguration command-line argument #319

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/main/java/se/liu/ida/hefquin/cli/RunBGPOverNeo4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -58,20 +49,14 @@ 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");
protected final ArgDecl argNoVarRepl = new ArgDecl(ArgDecl.NoValue, "disableVariableReplacement");
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();
}
Expand All @@ -85,6 +70,7 @@ protected RunBGPOverNeo4j( final String[] argv ) {
add(argSuppressResultPrintout, "--suppressResultPrintout", "Do not print out the query result");

addModule(modQuery);
addModule(modLPG2RDFConfiguration);
hartig marked this conversation as resolved.
Show resolved Hide resolved

add(argEndpointURI, "--endpoint", "The URI of the Neo4j endpoint");
add(argNaive, "--naive", "If you want naive translation");
Expand All @@ -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<CypherQuery, Map<CypherVar,Var>> tRes = performQueryTranslation(bgp, conf);
hartig marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 se.liu.ida.hefquin.engine.wrappers.lpgwrapper.LPG2RDFConfiguration;
import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.LPG2RDFConfigurationReader;

public class ModLPG2RDFConfiguration extends ModBase {
protected final ArgDecl lpg2RDFDescrDecl = new ArgDecl(ArgDecl.HasValue, "LPG2RDFConfigurationDescription", "lpg2rdf");

protected LPG2RDFConfiguration cat = null;

@Override
public void registerWith( final CmdGeneral cmdLine ) {
cmdLine.getUsage().startCategory("LPG2RDFConfigurationDescription");
cmdLine.add(lpg2RDFDescrDecl, "--LPG2RDFConfigurationDescription", "file with an RDF description of the LPG2RDFConfiguration");
hartig marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void processArgs( final CmdArgModule cmdLine ) {
if ( cmdLine.contains(lpg2RDFDescrDecl) ) {
final String lpg2RDFDescrFilename = cmdLine.getValue(lpg2RDFDescrDecl);
cat = LPG2RDFConfigurationReader.readFromFile(lpg2RDFDescrFilename);
}
}


public LPG2RDFConfiguration getLPG2RDFConfigurationCatalog() {
return cat;
hartig marked this conversation as resolved.
Show resolved Hide resolved
}

}
Loading