org.openrdf.repository.config.RepositoryConfigException Java Examples

The following examples show how to use org.openrdf.repository.config.RepositoryConfigException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BigdataRepositoryConfig.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void parse(Graph graph, Resource implNode)
	throws RepositoryConfigException
{
	super.parse(graph, implNode);

	try {
		Literal propertiesLit = GraphUtil.getOptionalObjectLiteral(
                   graph, implNode, BigdataConfigSchema.PROPERTIES);
		if (propertiesLit != null) {
			setPropertiesFile((propertiesLit).getLabel());
		} else {
               throw new RepositoryConfigException("Properties file required");
           }
	}
	catch (GraphUtilException e) {
		throw new RepositoryConfigException(e.getMessage(), e);
	}
}
 
Example #2
Source File: QueryServiceTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Before
public void resetQueryService() throws RepositoryConfigException, RepositoryException, InstantiationException, IllegalAccessException {
    this.anno4j = new Anno4j();
    queryService = anno4j.createQueryService();
    queryService.addPrefix("ex", "http://www.example.com/schema#");

    // Persisting some data
    Annotation annotation =  anno4j.createObject(Annotation.class);
    HashSet<Target> targets = new HashSet<>();
    SpecificResource specificResource =  anno4j.createObject(SpecificResource.class);
    SpecificResource resource2 =  anno4j.createObject(SpecificResource.class);
    resource2.setSelector( anno4j.createObject(SvgSelector.class));
    specificResource.setSelector(anno4j.createObject(FragmentSelector.class));
    targets.add(specificResource);
    targets.add(resource2);
    annotation.setTargets(targets);

}
 
Example #3
Source File: ObjectParser.java    From anno4j with Apache License 2.0 6 votes vote down vote up
/**
 * Basic constructor, which sets up all the necessary repositories.
 *
 * @throws RepositoryException Thrown if an error occurred accessing the created repository.
 * @throws RepositoryConfigException Thrown if an error occurred configuring the new repository.
 */
public ObjectParser() throws RepositoryException, RepositoryConfigException {
    this.anno4j = new Anno4j();
    URIImpl[] motivations = new URIImpl[]{
            new URIImpl(OADM.MOTIVATION_BOOKMARKING),
            new URIImpl(OADM.MOTIVATION_CLASSIFYING),
            new URIImpl(OADM.MOTIVATION_COMMENTING),
            new URIImpl(OADM.MOTIVATION_DESCRIBING),
            new URIImpl(OADM.MOTIVATION_EDITING),
            new URIImpl(OADM.MOTIVATION_HIGHLIGHTING),
            new URIImpl(OADM.MOTIVATION_IDENTIFYING),
            new URIImpl(OADM.MOTIVATION_LINKING),
            new URIImpl(OADM.MOTIVATION_MODERATING),
            new URIImpl(OADM.MOTIVATION_QUESTIONING),
            new URIImpl(OADM.MOTIVATION_REPLYING),
            new URIImpl(OADM.MOTIVATION_TAGGING)
    };

    URIImpl obj = new URIImpl(OADM.MOTIVATION);
    URIImpl pre = new URIImpl(RDF.TYPE);

    for (URIImpl sub : motivations) {
        StatementImpl statement = new StatementImpl(sub, pre, obj);
        anno4j.getRepository().getConnection().add(statement);
    }
}
 
Example #4
Source File: Anno4j.java    From anno4j with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the Repository (Connector for local/remote SPARQL repository) to use in Anno4j.
 *
 * @param repository Repository to use in Anno4j.
 * @param conceptJars URLs of JAR-files that are scanned for conceptsByIri.
 * @param behaviourJars URLs of JAR-files that are scanned for behaviours.
 * @throws RepositoryException
 * @throws RepositoryConfigException
 */
public void setRepository(Repository repository, Set<URL> conceptJars, Set<URL> behaviourJars) throws RepositoryException, RepositoryConfigException {
    this.repository = repository;
    // update alibaba wrapper

    ObjectRepositoryFactory factory = new ObjectRepositoryFactory();
    ObjectRepositoryConfig config = factory.getConfig();

    for(URL conceptJar : conceptJars) {
        config.addConceptJar(conceptJar);
    }
    for(URL behaviourJar : behaviourJars) {
        config.addBehaviourJar(behaviourJar);
    }

    if(partialClasses != null) {
        for(Class<?> clazz : this.partialClasses){
            if (!clazz.getSimpleName().endsWith("AbstractClass")) {
                config.addBehaviour(clazz);
            }
        }
    }

    this.objectRepository = new ObjectRepositoryFactory().createRepository(config, repository);
    this.objectRepository.setIdGenerator(idGenerator);
}
 
Example #5
Source File: RecursivePathTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
/**
 * Test method for OneOrMorePath
 *
 * @see <a href="http://www.w3.org/TR/sparql11-query/#pp-language">http://www.w3.org/TR/sparql11-query/#pp-language</a>
 */
public void oneOrMoreTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> annotations = queryService
            .addCriteria("(oa:hasTarget)+")
            .execute();
    assertEquals(0, annotations.size());

    super.setupUpQueryTest();

    annotations = queryService
            .addCriteria("(oa:hasBody)+")
            .addCriteria("oa:hasBody/ex:recursiveBodyValue", "Another Testing Value")
            .execute();
    assertEquals(1, annotations.size());
    assertEquals("Another Testing Value", ((RecursiveBody) annotations.get(0).getBodies().iterator().next()).getValue());
}
 
Example #6
Source File: RecursivePathTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
/**
 * Test method for ZeroOrMorePath.
 *
 * @see <a href="http://www.w3.org/TR/sparql11-query/#pp-language">http://www.w3.org/TR/sparql11-query/#pp-language</a>
 */
public void zeroOrMoreTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> annotations = queryService.addCriteria("(oa:hasBody/ex:recursiveBodyValue)*", "Some Testing Value").execute();
    assertEquals(1, annotations.size());
    assertEquals("Some Testing Value", ((RecursiveBody) annotations.get(0).getBodies().iterator().next()).getValue());

    super.setupUpQueryTest();

    annotations = queryService.addCriteria("(oa:hasTarget)*").execute();
    assertEquals(2, annotations.size());
}
 
Example #7
Source File: ObjectParserTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJSONLD() throws UpdateExecutionException {

    try {
        URL url = new URL("http://example.com/");

        ObjectParser objectParser = new ObjectParser();
        List<Annotation> annotations = objectParser.parse(JSONLD, url, RDFFormat.JSONLD, true);

        for(Annotation anno : annotations) {
            System.out.println(anno.toString());
        }

        assertEquals(1, annotations.size());

        objectParser.shutdown();
    } catch (RepositoryException | MalformedURLException | RepositoryConfigException e) {
        e.printStackTrace();
    }
}
 
Example #8
Source File: ObjectParserTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testTurtle() throws UpdateExecutionException {
    try {
        URL url = new URL("http://example.com/");

        ObjectParser objectParser = new ObjectParser();
        List<Annotation> annotations = objectParser.parse(TURTLE, url, RDFFormat.TURTLE, true);

        for(Annotation anno : annotations) {
            System.out.println(anno.toString());
        }

        assertEquals(1, annotations.size());

        objectParser.shutdown();
    } catch (IOException | RepositoryException | RepositoryConfigException e) {
        e.printStackTrace();
    }
}
 
Example #9
Source File: ObjectParserTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleTurtle() throws UpdateExecutionException {
    try {
        URL url = new URL("http://example.com/");

        ObjectParser objectParser = new ObjectParser();

        List<Annotation> annotations = new LinkedList<>();
        annotations.addAll(objectParser.parse(TURTLE, url, RDFFormat.TURTLE, true));
        annotations.addAll(objectParser.parse(TURTLE2, url, RDFFormat.TURTLE, true));
        annotations.addAll(objectParser.parse(TURTLE3, url, RDFFormat.TURTLE, true));

        assertEquals(3, annotations.size());

        for(Annotation anno : annotations) {
            System.out.println(anno.toString());
        }

        objectParser.shutdown();
    } catch (IOException | RepositoryException | RepositoryConfigException e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: ObjectParserTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleInOneTurtle() throws UpdateExecutionException {
    try {
        URL url = new URL("http://example.com/");

        ObjectParser objectParser = new ObjectParser();
        List<Annotation> annotations = objectParser.parse(TURTLE_MULTIPLE, url, RDFFormat.TURTLE, true);

        assertEquals(3, annotations.size());

        for(Annotation anno : annotations) {
            System.out.println(anno.toString());
        }

        objectParser.shutdown();
    } catch (IOException | RepositoryException | RepositoryConfigException e) {
        e.printStackTrace();
    }
}
 
Example #11
Source File: BigdataRepositoryFactory.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public Repository getRepository(final RepositoryImplConfig config)
	throws RepositoryConfigException {

	if (!TYPE.equals(config.getType())) {
		throw new RepositoryConfigException(
                   "Invalid type: " + config.getType());
	}
	
	if (!(config instanceof BigdataRepositoryConfig)) {
		throw new RepositoryConfigException(
                   "Invalid type: " + config.getClass());
	}
	
       try {
           
		final BigdataRepositoryConfig bigdataConfig = (BigdataRepositoryConfig)config;
		final Properties properties = bigdataConfig.getProperties();
   		final BigdataSail sail = new BigdataSail(properties);
   		return new BigdataSailRepository(sail);
           
       } catch (Exception ex) {
           throw new RepositoryConfigException(ex);
       }
       
}
 
Example #12
Source File: ResourceObjectSupportTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a RDF document to a certain context of a Anno4j-connected repository.
 * @param type The type of resources to read.
 * @param anno4j The Anno4j object to read to.
 * @param rdfDocument The RDF document to read.
 * @param documentUrl The URL of the document.
 * @param format The format of the document.
 * @param context The context to which the RDF data should be read. A value of null corresponds to the default graph.
 * @param <T> The type of resources to read.
 * @throws RepositoryException Thrown if an error occurs accessing the repository of the Anno4j object or the intermediate repository.
 * @throws RDFParseException Thrown if an error occurs parsing the given RDF document in the given format.
 */
private <T extends ResourceObject> void parseRDF(Class<T> type, Anno4j anno4j, String rdfDocument, URL documentUrl, RDFFormat format, URI context) throws RepositoryException, RDFParseException {
    // Parse the RDF document using ObjectParser:
    ObjectParser parser = null;
    try {
        parser = new ObjectParser();
    } catch (RepositoryConfigException e) {
        throw new RepositoryException(e);
    }
    List<T> resources = parser.parse(type, rdfDocument, documentUrl, format, false);

    for (T resource : resources) {
        anno4j.persist(resource, context);
    }
}
 
Example #13
Source File: LogicalTests.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void logicalNotTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> list = queryService.addCriteria("oa:hasBody/ex:languageValue[!(@de | @en)]").execute();
    assertEquals(0, list.size());

    super.setupUpQueryTest();

    List<Annotation> list2 = queryService.addCriteria("oa:hasBody/ex:languageValue[!@de]").execute();
    assertEquals(1, list2.size());

    super.setupUpQueryTest();

    List<Annotation> list3 = queryService.addCriteria("oa:hasBody/ex:languageValue[!@en]").execute();
    assertEquals(1, list3.size());
}
 
Example #14
Source File: LogicalTests.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void logicalAndTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> list = queryService.addCriteria("oa:hasBody[ex:logicalTestFirstValue is \"First Value\"  & ex:logicalTestAnotherValue is \"Another Value\"]").execute();
    assertEquals(1, list.size());
    FirstLogicalTestBody firstLogicalTestBody = (FirstLogicalTestBody) list.get(0).getBodies().iterator().next();
    assertEquals("First Value", firstLogicalTestBody.getValue());
    assertEquals("Another Value", firstLogicalTestBody.getAnotherValue());

    super.setupUpQueryTest();

    List<Annotation> list1 = queryService.addCriteria("oa:hasBody[rdf:type is ex:firstLogicalBodyType  & ex:logicalTestAnotherValue is \"Another Value\"]").execute();
    assertEquals(1, list1.size());
    assertEquals("Another Value", ((FirstLogicalTestBody) list.get(0).getBodies().iterator().next()).getAnotherValue());
}
 
Example #15
Source File: LogicalTests.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void logicalOrTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {

    List<Annotation> list = queryService.addCriteria("oa:hasBody[is-a ex:firstLogicalBodyType  | is-a ex:secondLogicalBodyType]").execute();
    assertEquals(2, list.size());

    super.setupUpQueryTest();

    List<Annotation> list1 = queryService.addCriteria("oa:hasBody/ex:languageValue[@de]").execute();
    assertEquals(1, list1.size());
    FirstLogicalTestBody firstLogicalTestBody = (FirstLogicalTestBody) list1.get(0).getBodies().iterator().next();
    assertEquals(firstLogicalTestBody.getLangValue().toString(), "Testwert");

    super.setupUpQueryTest();

    List<Annotation> list2 = queryService.addCriteria("oa:hasBody/ex:languageValue[@en]").execute();
    assertEquals(1, list2.size());
    SecondLogicalTestBody secondLogicalTestBody = (SecondLogicalTestBody) list2.get(0).getBodies().iterator().next();
    assertEquals(secondLogicalTestBody.getLangValue().toString(), "Second Body Lang Value");

    super.setupUpQueryTest();

    List list3 = queryService.addCriteria("oa:hasBody/ex:languageValue[@en | @de]").execute();
    assertEquals(2, list3.size());

    super.setupUpQueryTest();

    List list4 = queryService.addCriteria("oa:hasBody/ex:languageValue[@es | @de]").execute();
    assertEquals(1, list4.size());
}
 
Example #16
Source File: ObjectRepositoryFactory.java    From anno4j with Apache License 2.0 5 votes vote down vote up
/**
 * Wrap a previously initialised repository in an ObjectRepository.
 */
public ObjectRepository createRepository(ObjectRepositoryConfig config,
		Repository delegate) throws RepositoryConfigException,
		RepositoryException {
	ObjectRepository repo = getRepository(config, delegate.getValueFactory());
	repo.setDelegate(delegate);
	return repo;
}
 
Example #17
Source File: PathEqualityTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void bothBodyTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> list1 = queryService.addCriteria("oa:hasBody[ex:pathEqualityTestAnotherValue is \"Another Value\"]").execute();
    assertEquals(2, list1.size());

    FirstPathEqualityTestBody firstPathEqualityTestBody = (FirstPathEqualityTestBody) list1.get(0).getBodies().iterator().next();
    assertEquals("First Value", firstPathEqualityTestBody.getValue());
    assertEquals("Another Value", firstPathEqualityTestBody.getAnotherValue());

    SecondPathEqualityTestBody secondPathEqualityTestBody = (SecondPathEqualityTestBody) list1.get(1).getBodies().iterator().next();
    assertEquals("Second Value", secondPathEqualityTestBody.getValue());
    assertEquals("Another Value", secondPathEqualityTestBody.getAnotherValue());
}
 
Example #18
Source File: ObjectRepositoryFactory.java    From anno4j with Apache License 2.0 5 votes vote down vote up
/**
 * Create an uninitialised ObjectRepository without a delegate.
 */
@Override
public ObjectRepository getRepository(RepositoryImplConfig configuration)
		throws RepositoryConfigException {
	if (!(configuration instanceof ObjectRepositoryConfig))
		throw new RepositoryConfigException("Invalid configuration class: "
				+ configuration.getClass());
	ObjectRepositoryConfig config = (ObjectRepositoryConfig) configuration;
	return getRepository(config, ValueFactoryImpl.getInstance());
}
 
Example #19
Source File: PathEqualityTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void secondBodyTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> list1 = queryService.addCriteria("oa:hasBody[ex:pathEqualityTestSecondValue is \"Second Value\"]").execute();
    assertEquals(1, list1.size());

    SecondPathEqualityTestBody secondPathEqualityTestBody = (SecondPathEqualityTestBody) list1.get(0).getBodies().iterator().next();
    assertEquals("Second Value", secondPathEqualityTestBody.getValue());
    assertEquals("Another Value", secondPathEqualityTestBody.getAnotherValue());
}
 
Example #20
Source File: PathEqualityTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void inequalityTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> list = queryService.addCriteria("oa:hasBody[!ex:pathEqualityTestFirstValue is \"First Value\"]").execute();
    assertEquals(1, list.size());

    FirstPathEqualityTestBody firstPathEqualityTestBody = (FirstPathEqualityTestBody) list.get(0).getBodies().iterator().next();
    assertEquals("Second Value", firstPathEqualityTestBody.getValue());
}
 
Example #21
Source File: PathEqualityTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void firstBodyTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException, RepositoryConfigException, IllegalAccessException, InstantiationException {
    List<Annotation> list = queryService.addCriteria("oa:hasBody[ex:pathEqualityTestFirstValue is \"First Value\"]").execute();
    assertEquals(1, list.size());

    FirstPathEqualityTestBody firstPathEqualityTestBody = (FirstPathEqualityTestBody) list.get(0).getBodies().iterator().next();
    assertEquals("First Value", firstPathEqualityTestBody.getValue());
    assertEquals("Another Value", firstPathEqualityTestBody.getAnotherValue());
}
 
Example #22
Source File: FragmentSelectorSupport.java    From anno4j with Apache License 2.0 4 votes vote down vote up
@Override
public ResourceObject getConformsTo() throws RepositoryConfigException, RepositoryException, InstantiationException, IllegalAccessException {
    Anno4j anno4j = new Anno4j(this.getObjectConnection().getRepository());

    return SelectorFactory.getMediaFragmentsSpecification(anno4j);
}
 
Example #23
Source File: SvgSelectorSupport.java    From anno4j with Apache License 2.0 4 votes vote down vote up
@Override
public ResourceObject getConformsTo() throws RepositoryConfigException, RepositoryException, InstantiationException, IllegalAccessException {
    Anno4j anno4j = new Anno4j(this.getObjectConnection().getRepository());

    return SelectorFactory.getSvgSpecification(anno4j);
}
 
Example #24
Source File: ObjectRepositoryFactory.java    From anno4j with Apache License 2.0 4 votes vote down vote up
/**
 * Wrap a previously initialised repository in an ObjectRepository.
 */
public ObjectRepository createRepository(Repository delegate)
		throws RepositoryConfigException, RepositoryException {
	return createRepository(getConfig(), delegate);
}
 
Example #25
Source File: Anno4j.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public Anno4j() throws RepositoryException, RepositoryConfigException {
    this(new SailRepository(new MemoryStore()));
}
 
Example #26
Source File: Anno4j.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public Anno4j(boolean persistSchemaAnnotations) throws RepositoryException, RepositoryConfigException {
    this(new SailRepository(new MemoryStore()), null, persistSchemaAnnotations);
}
 
Example #27
Source File: Anno4j.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public Anno4j(URI defaultContext) throws RepositoryException, RepositoryConfigException {
    this(new SailRepository(new MemoryStore()), defaultContext);
}
 
Example #28
Source File: Anno4j.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public Anno4j(IDGenerator idGenerator) throws RepositoryException, RepositoryConfigException {
    this(new SailRepository(new MemoryStore()), idGenerator, null, true);
}
 
Example #29
Source File: Anno4j.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public Anno4j(IDGenerator idGenerator, URI defaultContext) throws RepositoryException, RepositoryConfigException {
    this(new SailRepository(new MemoryStore()), idGenerator, defaultContext, true);
}
 
Example #30
Source File: InputOutputTest.java    From anno4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testInputAndOutput() throws RepositoryException, IllegalAccessException, InstantiationException, RepositoryConfigException, MalformedURLException, UpdateExecutionException, MalformedQueryException, ParseException, QueryEvaluationException {
    Annotation annotation = this.anno4j.createObject(Annotation.class);

    SpecificResource specificResource = this.anno4j.createObject(SpecificResource.class);
    ResourceObject source = this.anno4j.createObject(ResourceObject.class);
    specificResource.setSource(source);

    TextualBody textualBody = this.anno4j.createObject(TextualBody.class);
    textualBody.setValue("someText");

    annotation.addTarget(specificResource);
    annotation.addBody(textualBody);

    // Create JSONLD of the Annotation
    String jsonld = annotation.getTriples(RDFFormat.JSONLD);

    System.out.println("JsonLD representation of the Annotation:");
    System.out.println(jsonld);

    // Parse the JSONLD String
    ObjectParser parser = new ObjectParser();
    List<Annotation> parsed = parser.parse(jsonld, new URL("http://example.com/"), RDFFormat.JSONLD, false);

    assertEquals(1, parsed.size());
    assertEquals(annotation.getResourceAsString(), parsed.get(0).getResourceAsString());

    // Get the JSONLD of the parsed Annotation object
    Annotation parsedAnnotation = parsed.get(0);

    String jsonldParsed = parsedAnnotation.getTriples(RDFFormat.RDFXML);

    System.out.println("JsonLD representation of the PARSED Annotation:");
    System.out.println(jsonldParsed);

    parser.shutdown();

    // Write Annotations to "real" Anno4j and query them afterwards works, but is really inconvenient
    //        this.anno4j.getObjectRepository().getConnection().addObject(parsedAnnotation);
    //
    //        parsedAnnotation.setResourceAsString(parsedAnnotation.getResourceAsString() + "1");
    //        QueryService qs = this.anno4j.createQueryService();
    //        qs.addCriteria(".", parsedAnnotation.getResourceAsString());
    //
    //        Annotation queriedAnnotation = qs.execute(Annotation.class).get(0);
}