Example #1
0
  public Atom<List<Map<String, Vertex>>> compute(
      final List<Operation> arguments, final GremlinScriptContext context) throws RuntimeException {

    final int size = arguments.size();
    final SailGraph graph = (SailGraph) FunctionHelper.getGraph(arguments, 0, context);

    final String sparqlQuery;

    if (size == 1) {
      sparqlQuery = (String) arguments.get(0).compute().getValue();
    } else if (size == 2) {
      sparqlQuery = (String) arguments.get(1).compute().getValue();
    } else {
      throw new RuntimeException(this.createUnsupportedArgumentMessage());
    }

    return new Atom<List<Map<String, Vertex>>>(graph.executeSparql(sparqlQuery));
  }
  public void testRemoveNamespace() {
    SailGraph graph = new MemoryStoreSailGraph();
    GremlinScriptContext context = new GremlinScriptContext();
    context
        .getBindings(ScriptContext.ENGINE_SCOPE)
        .put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(graph));

    Function<Object> function = new RemoveNamespaceFunction();
    assertNotNull(graph.getNamespaces().get("rdf"));
    this.stopWatch();
    Atom<Object> atom = function.compute(createUnaryArgs(graph, "rdf"), context);
    printPerformance(
        function.getFunctionName() + " function", 1, "namespace removed", this.stopWatch());
    assertNull(atom.getValue());
    assertNull(graph.getNamespaces().get("rdf"));

    assertNotNull(graph.getNamespaces().get("rdfs"));
    this.stopWatch();
    atom = function.compute(createUnaryArgs("rdfs"), context);
    printPerformance(
        function.getFunctionName() + " function", 1, "namespace removed", this.stopWatch());
    assertTrue(atom.isNull());
    assertNull(graph.getNamespaces().get("rdfs"));

    graph.shutdown();
  }