Search in sources :

Example 11 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RepositoryManager method isSafeToRemove.

/**
 * Checks on whether the given repository is referred to by a
 * {@link org.eclipse.rdf4j.repository.sail.ProxyRepository} configuration.
 *
 * @param repositoryID
 *        id to check
 * @return true if there is no existing proxy reference to the given id, false otherwise
 * @throws RepositoryException
 */
public boolean isSafeToRemove(String repositoryID) throws RepositoryException {
    SimpleValueFactory vf = SimpleValueFactory.getInstance();
    for (String id : getRepositoryIDs()) {
        RepositoryConfig config = getRepositoryConfig(id);
        Model model = new LinkedHashModel();
        config.export(model, vf.createBNode());
        if (model.contains(null, PROXIED_ID, vf.createLiteral(repositoryID))) {
            return false;
        }
    }
    return true;
}
Also used : RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory)

Example 12 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project molgenis by molgenis.

the class EntityModelWriter method createEmptyModel.

public Model createEmptyModel() {
    Model model = new LinkedHashModel();
    setNamespacePrefixes(model);
    return model;
}
Also used : LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 13 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project molgenis by molgenis.

the class FairController method handleUnknownEntityException.

@ExceptionHandler(UnknownEntityException.class)
@ResponseBody
@ResponseStatus(BAD_REQUEST)
public Model handleUnknownEntityException(UnknownEntityException e) {
    LOG.warn(e.getMessage(), e);
    Model emptyModel = new LinkedHashModel();
    return emptyModel;
}
Also used : LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 14 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project opentheso by miledrousset.

the class ReadRdfFile_rdf4j method readFile.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
@Test
public void readFile() {
    File file = new File("/Users/Miled/Desktop/Bureau2/test_unesco.rdf");
    RDFParser rdfParser = Rio.createParser(RDFFormat.RDFXML);
    Model model = new LinkedHashModel();
    rdfParser.setRDFHandler(new StatementCollector(model));
    Rio.write(model, System.out, RDFFormat.TURTLE);
    try {
        rdfParser.parse(new FileReader(file), "http://example.org");
        /*       for (Statement statement : model) {
                
        //        writeLine(statement.getObject().stringValue(), statement.getSubject().stringValue());

                System.out.println("LocalName = " + statement.getPredicate().getLocalName());

                System.out.println("objet = " + statement.getObject().stringValue());
                System.out.println("predicat = " + statement.getPredicate());
                System.out.println("URI = " + statement.getSubject());
                System.out.println("");
               
           //     model.getNamespace(statement.getClass().getgetObject().stringValue());

            } */
        for (Statement statement2 : model) {
            Literal literal = (SimpleLiteral) statement2;
            System.out.println(literal.getLabel());
            // System.out.println(literal.getLanguage());
            System.out.println(literal.getDatatype());
        }
    } catch (IOException e) {
    // handle IO problems (e.g. the file could not be read)
    } catch (RDFParseException e) {
    // handle unrecoverable parse error
    } catch (RDFHandlerException e) {
    // handle a problem encountered by the RDFHandler
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) Statement(org.eclipse.rdf4j.model.Statement) Literal(org.eclipse.rdf4j.model.Literal) SimpleLiteral(org.eclipse.rdf4j.model.impl.SimpleLiteral) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) FileReader(java.io.FileReader) SimpleLiteral(org.eclipse.rdf4j.model.impl.SimpleLiteral) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) IOException(java.io.IOException) RDFParser(org.eclipse.rdf4j.rio.RDFParser) File(java.io.File) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 15 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project molgenis by molgenis.

the class EntityModelWriterTest method testAddStatementsForEntityType.

@Test
public void testAddStatementsForEntityType() {
    Model model = new LinkedHashModel();
    Resource subject = valueFactory.createIRI("http://example.org/subject");
    LabeledResource object = new LabeledResource("http://example.org/object", "object");
    LabeledResource codeSystem = new LabeledResource("ex:object");
    SemanticTag<EntityType, LabeledResource, LabeledResource> tag = new SemanticTag<>("tagId", entityType, Relation.isAssociatedWith, object, codeSystem);
    when(tagService.getTagsForEntity(entityType)).thenReturn(singletonList(tag));
    writer.addStatementsForEntityTags(model, subject, entityType);
    Statement statement = valueFactory.createStatement(subject, TYPE, valueFactory.createIRI("http://example.org/object"));
    assertEquals(newArrayList(model), singletonList(statement));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) LabeledResource(org.molgenis.data.semantic.LabeledResource) Statement(org.eclipse.rdf4j.model.Statement) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Resource(org.eclipse.rdf4j.model.Resource) LabeledResource(org.molgenis.data.semantic.LabeledResource) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) SemanticTag(org.molgenis.data.semantic.SemanticTag) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)30 Model (org.eclipse.rdf4j.model.Model)23 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)11 Test (org.junit.Test)11 RDFParser (org.eclipse.rdf4j.rio.RDFParser)7 ParseErrorCollector (org.eclipse.rdf4j.rio.helpers.ParseErrorCollector)7 ParserConfig (org.eclipse.rdf4j.rio.ParserConfig)6 Statement (org.eclipse.rdf4j.model.Statement)5 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)5 Literal (org.eclipse.rdf4j.model.Literal)4 Before (org.junit.Before)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 IRI (org.eclipse.rdf4j.model.IRI)3 Resource (org.eclipse.rdf4j.model.Resource)3 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)2 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)2 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)2 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2