Search in sources :

Example 51 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Remote_PathQL_MultiGraphTests method test_50.

/**
 * Test 50.
 */
@Test
@Order(50)
void test_50() {
    try {
        // Graph graph = source.addGraph("<http://inova8.com/calc2graph/testGraph5>");
        // source.removeGraph("<http://inova8.com/calc2graph/testGraph1>");
        Graph graph = source.openGraph("<http://inova8.com/calc2graph/testGraph5>");
        Thing myCountry = graph.getThing(":Country1");
        String performanceCalculation = "2*3";
        myCountry.addFact(":Attribute@:salesPerformance", performanceCalculation, SCRIPT.GROOVY);
        ResourceResults results = myCountry.getFacts(":Attribute@:salesPerformance");
        // if(results.hasNext()) {
        for (Resource result : results) {
            assertEquals("6", result.getValue().stringValue());
            break;
        }
        // source.removeGraph("<http://inova8.com/calc2graph/testGraph>");
        source.closeGraph("<http://inova8.com/calc2graph/testGraph5>");
    // }else {
    // fail();
    // }
    } catch (Exception e) {
        fail();
    }
}
Also used : Resource(com.inova8.intelligentgraph.model.Resource) Thing(com.inova8.intelligentgraph.model.Thing) ResourceResults(com.inova8.intelligentgraph.results.ResourceResults) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 52 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphRepository method addGraph.

/**
 * Adds the graph.
 *
 * @param graphName the graph name
 * @return the graph
 */
public Graph addGraph(String graphName) {
    ContextAwareConnection connection = this.getContextAwareConnection();
    Model result;
    IRI graphNameIri = null;
    try {
        graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
        result = new LinkedHashModel();
        ((Model) result).add(graphNameIri, SCRIPT.CACHE_DATE_TIME, literal(new Date()), graphNameIri);
        ((Model) result).add(graphNameIri, SCRIPT.ISPRIVATE, literal(true), graphNameIri);
        connection.add((Model) result, graphNameIri);
        Graph addedGraph = new Graph(this, graphNameIri);
        graphs.put(graphNameIri, addedGraph);
        getPublicContexts().add(graphNameIri);
        logger.debug("Added new graph {} ", graphNameIri.stringValue());
    } catch (Exception qe) {
        throw new ServerException(FAILEDTOADDGRAPH_EXCEPTION, String.format("Failed to add graph %s with exception %s", graphName, qe.getMessage()), qe);
    }
    return new Graph(this, graphNameIri);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) ContextAwareConnection(org.eclipse.rdf4j.repository.contextaware.ContextAwareConnection) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Date(java.util.Date) NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ScriptException(javax.script.ScriptException) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 53 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphRepository method create.

/**
 * Creates the.
 *
 * @param intelligentGraphConnection the intelligent graph connection
 * @return the intelligent graph repository
 */
public static IntelligentGraphRepository create(IntelligentGraphConnection intelligentGraphConnection) {
    IntelligentGraphSail sail = intelligentGraphConnection.getIntelligentGraphSail();
    Integer key = sail.hashCode();
    if (pathQLRepositories.containsKey(key)) {
        return pathQLRepositories.get(key);
    } else {
        IntelligentGraphRepository pathQLRepository = new IntelligentGraphRepository(intelligentGraphConnection);
        pathQLRepositories.put(key, pathQLRepository);
        return pathQLRepository;
    }
}
Also used : IntelligentGraphSail(com.inova8.intelligentgraph.sail.IntelligentGraphSail)

Example 54 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphRepository method openGraph.

/**
 * Open graph.
 *
 * @param graphName the graph name
 * @return the graph
 */
public Graph openGraph(String graphName) {
    // .getContextAwareConnection();
    RepositoryConnection connection = this.getRepository().getConnection();
    IRI graphNameIri = null;
    try {
        graphNameIri = PathParser.parseIriRef(getRepositoryContext(), graphName).getIri();
        @SuppressWarnings("deprecation") Boolean contextExists = connection.getContextIDs().asList().contains(graphNameIri);
        if (!contextExists) {
            addGraph(graphName);
        } else {
            getPublicContexts().add(graphNameIri);
        }
        logger.debug("Got graph {} ", graphNameIri.stringValue());
    } catch (Exception qe) {
        throw new ServerException(FAILEDTOOPENGRAPH_EXCEPTION, String.format("Failed to get graph %s with exception %s", graphName, qe.getMessage()), qe);
    }
    return new Graph(this, graphNameIri);
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) IRI(org.eclipse.rdf4j.model.IRI) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) NullValueReturnedException(com.inova8.intelligentgraph.exceptions.NullValueReturnedException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) ScriptException(javax.script.ScriptException) ServerException(com.inova8.intelligentgraph.exceptions.ServerException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 55 with Graph

use of com.inova8.intelligentgraph.intelligentGraphRepository.Graph in project com.inova8.intelligentgraph by peterjohnlawrence.

the class Thing method create.

/**
 * Creates the.
 *
 * @param source the source
 * @param graphIri the graph iri
 * @param superValue the super value
 * @param evaluationContext the evaluation context
 * @return the thing
 */
@SuppressWarnings("deprecation")
public static Thing create(IntelligentGraphRepository source, IRI graphIri, org.eclipse.rdf4j.model.Value superValue, EvaluationContext evaluationContext) {
    Thing thing;
    // graphIri.stringValue()+"~"+ superValue.stringValue();
    String graphThingKey = superValue.stringValue();
    if (superValue != null && source != null && source.getThings().containsKey(graphThingKey)) {
        thing = source.getThings().get(graphThingKey);
        thing.setSource(source);
        if (evaluationContext != null) {
            // if(thing.evaluationContext.getPrefixes()==null || thing.evaluationContext.getPrefixes().isEmpty())thing.evaluationContext.setPrefixes(evaluationContext.getPrefixes());
            if (evaluationContext.getCustomQueryOptions() != null && !evaluationContext.getCustomQueryOptions().isEmpty())
                thing.evaluationContext.setCustomQueryOptions(evaluationContext.getCustomQueryOptions());
            if (evaluationContext.getTracer() != null && evaluationContext.getTracer().isTracing())
                thing.evaluationContext.setTracer(evaluationContext.getTracer());
            if (evaluationContext.getDataset() != null)
                thing.evaluationContext.setDataset(evaluationContext.getDataset());
            thing.evaluationContext.setContexts(evaluationContext.getContexts());
        }
        // Overwrite the graphName if not null
        if (graphIri != null)
            thing.graphName = graphIri;
        return thing;
    } else {
        thing = new Thing(source, superValue, evaluationContext);
        if (source != null)
            source.getThings().put(graphThingKey, thing);
        if (graphIri == null)
            graphIri = Graph.DEFAULTGRAPH;
        thing.graphName = graphIri;
    }
    if (evaluationContext != null)
        thing.evaluationContext = evaluationContext;
    else if (thing.evaluationContext == null)
        thing.evaluationContext = new EvaluationContext();
    return thing;
}
Also used : EvaluationContext(com.inova8.intelligentgraph.evaluator.EvaluationContext)

Aggregations

Thing (com.inova8.intelligentgraph.model.Thing)53 Graph (com.inova8.intelligentgraph.intelligentGraphRepository.Graph)45 Order (org.junit.jupiter.api.Order)44 Test (org.junit.jupiter.api.Test)44 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)44 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)22 Resource (com.inova8.intelligentgraph.model.Resource)22 ResourceResults (com.inova8.intelligentgraph.results.ResourceResults)14 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)13 PathPatternException (com.inova8.pathql.processor.PathPatternException)12 RecognitionException (org.antlr.v4.runtime.RecognitionException)12 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)8 Repository (org.eclipse.rdf4j.repository.Repository)8 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)6 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)5 ServerException (com.inova8.intelligentgraph.exceptions.ServerException)5 ScriptException (javax.script.ScriptException)5 IRI (org.eclipse.rdf4j.model.IRI)5 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)5 Trace (com.inova8.intelligentgraph.evaluator.Trace)4