local runner support specify a graph state class name

This commit is contained in:
youdonghai 2023-12-21 10:16:27 +08:00
parent 52ca5d8a4d
commit 1eadad5ddd
3 changed files with 24 additions and 18 deletions

View File

@ -176,26 +176,28 @@ public class KGReasonerLocalRunner {
return graphState;
}
String graphLoadClass = task.getGraphLoadClass();
MemGraphState memGraphState = new MemGraphState();
AbstractLocalGraphLoader graphLoader;
if (StringUtils.isEmpty(task.getGraphStateInitString())) {
String graphStateClass = task.getGraphStateClassName();
if (StringUtils.isNotEmpty(graphStateClass)) {
try {
graphLoader =
(AbstractLocalGraphLoader) Class.forName(graphLoadClass).getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e);
}
} else {
try {
graphLoader =
(AbstractLocalGraphLoader)
Class.forName(graphLoadClass)
graphState =
(GraphState<IVertexId>)
Class.forName(graphStateClass)
.getConstructor(String.class)
.newInstance(task.getGraphStateInitString());
} catch (Exception e) {
throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e);
throw new RuntimeException("can not create graph state from name " + graphStateClass, e);
}
return graphState;
}
String graphLoadClass = task.getGraphLoadClass();
MemGraphState memGraphState = new MemGraphState();
AbstractLocalGraphLoader graphLoader;
try {
graphLoader =
(AbstractLocalGraphLoader) Class.forName(graphLoadClass).getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e);
}
graphLoader.setGraphState(memGraphState);
graphLoader.load();

View File

@ -217,7 +217,7 @@ public class LocalRunnerMain {
task.setDsl(dsl);
task.setOutputFile(outputFile);
task.setConnInfo(new KgSchemaConnectionInfo(schemaUri, schemaToken));
task.setGraphLoadClass(graphStateClass);
task.setGraphStateClassName(graphStateClass);
task.setGraphStateInitString(graphStateUrl);
task.setStartIdList(new ArrayList<>());
task.addStartId(startIdList);

View File

@ -51,12 +51,16 @@ public class LocalReasonerTask implements Serializable {
private KgSchemaConnectionInfo connInfo = null;
private String schemaString = null;
/** Choose between graphLoadClass or graphState */
/** Choose between graphLoadClass and graphState, or specify a class name */
private String graphLoadClass = null;
private String graphStateInitString = null;
private GraphState<IVertexId> graphState = null;
/** User specified the name of graphstate */
private String graphStateClassName = null;
private String graphStateInitString = null;
/** start id from input */
private List<Tuple2<String, String>> startIdList;