use of org.eclipse.rdf4j.model.Statement in project opentheso by miledrousset.
the class ReadRdf4j method readModel.
/**
* Permet de lire un fichier RDF précédament charger avec la fonction
* laodModel() les données sont stoqué dans la variable thesaurus
*/
private void readModel(rdf4jFileBean fileBean) {
ReadStruct readStruct = new ReadStruct();
readStruct.resource = null;
// pour le debug :
ArrayList<String> nonReco = new ArrayList();
for (Statement st : model) {
readStruct.value = st.getObject();
readStruct.property = st.getPredicate();
if (readStruct.value instanceof Literal) {
readStruct.literal = (Literal) readStruct.value;
}
// Concept or ConceptScheme or Collection or ConceptGroup
if (readStruct.property.getLocalName().equals("type")) {
int prop = -1;
String type = readStruct.value.toString();
type = type.toUpperCase();
if (type.contains("ConceptScheme".toUpperCase())) {
prop = SKOSProperty.ConceptScheme;
sKOSXmlDocument.setTitle(st.getSubject().stringValue());
} else if (type.contains("ConceptGroup".toUpperCase())) {
prop = SKOSProperty.ConceptGroup;
} else if (type.contains("Theme".toUpperCase())) {
prop = SKOSProperty.Theme;
} else if (type.contains("MicroThesaurus".toUpperCase())) {
prop = SKOSProperty.MicroThesaurus;
} else if (type.contains("Collection".toUpperCase())) {
prop = SKOSProperty.Collection;
} else if (type.contains("Concept".toUpperCase())) {
prop = SKOSProperty.Concept;
}
String uri = st.getSubject().stringValue();
readStruct.resource = new SKOSResource(uri, prop);
if (prop == SKOSProperty.ConceptScheme) {
sKOSXmlDocument.setConceptScheme(readStruct.resource);
} else if (prop == SKOSProperty.ConceptGroup || prop == SKOSProperty.Collection || prop == SKOSProperty.Theme || prop == SKOSProperty.MicroThesaurus) {
sKOSXmlDocument.addGroup(readStruct.resource);
} else if (prop == SKOSProperty.Concept) {
sKOSXmlDocument.addconcept(readStruct.resource);
}
} else // Labelling Properties
if (readLabellingProperties(readStruct)) {
// Dates
if (readDate(readStruct)) {
// Semantic Relationships
if (readRelationships(readStruct)) {
// Documentation Properties
if (readDocumentation(readStruct)) {
if (readCreator(readStruct)) {
if (readGPSCoordinates(readStruct)) {
if (readNotation(readStruct)) {
if (readIdentifier(readStruct)) {
if (readMatch(readStruct)) {
// debug
if (!nonReco.contains(readStruct.property.getLocalName())) {
// System.out.println("non reconue : " + readStruct.property.getLocalName());
nonReco.add(readStruct.property.getLocalName());
}
}
}
}
}
}
}
}
}
}
}
if (!nonReco.isEmpty()) {
String balises = "";
for (String b : nonReco) {
balises += " " + b + "\n";
}
fileBean.setWarning("Not readed RDF tag\n" + balises);
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class JSONLDWriterBackgroundTest method testRoundTripNamespaces.
@Test
public void testRoundTripNamespaces() throws Exception {
String exNs = "http://example.org/";
IRI uri1 = vf.createIRI(exNs, "uri1");
IRI uri2 = vf.createIRI(exNs, "uri2");
Literal plainLit = vf.createLiteral("plain", XMLSchema.STRING);
Statement st1 = vf.createStatement(uri1, uri2, plainLit);
ByteArrayOutputStream out = new ByteArrayOutputStream();
RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
rdfWriter.getWriterConfig().set(JSONLDSettings.JSONLD_MODE, JSONLDMode.COMPACT);
rdfWriter.handleNamespace("ex", exNs);
rdfWriter.startRDF();
rdfWriter.handleStatement(st1);
rdfWriter.endRDF();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
RDFParser rdfParser = rdfParserFactory.getParser();
ParserConfig config = new ParserConfig();
config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true);
config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true);
rdfParser.setParserConfig(config);
rdfParser.setValueFactory(vf);
Model model = new LinkedHashModel();
rdfParser.setRDFHandler(new StatementCollector(model));
rdfParser.parse(in, "foo:bar");
assertEquals("Unexpected number of statements, found " + model.size(), 1, model.size());
assertTrue("missing namespaced statement", model.contains(st1));
if (rdfParser.getRDFFormat().supportsNamespaces()) {
assertTrue("Expected at least one namespace, found " + model.getNamespaces().size(), model.getNamespaces().size() >= 1);
assertEquals(exNs, model.getNamespace("ex").get().getName());
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class NQuadsHandlingTest method writeNQuads.
/**
* Helper method to write the given model to N-Triples and return an InputStream containing the results.
*
* @param statements
* @return An {@link InputStream} containing the results.
* @throws RDFHandlerException
*/
private InputStream writeNQuads(Model statements) throws RDFHandlerException {
StringWriter writer = new StringWriter();
RDFWriter nQuadsWriter = new NQuadsWriter(writer);
nQuadsWriter.startRDF();
for (Statement nextStatement : statements) {
nQuadsWriter.handleStatement(nextStatement);
}
nQuadsWriter.endRDF();
return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class NTriplesHandlingTest method writeNTriples.
/**
* Helper method to write the given model to N-Triples and return an InputStream containing the results.
*
* @param statements
* @return An {@link InputStream} containing the results.
* @throws RDFHandlerException
*/
private InputStream writeNTriples(Model statements) throws RDFHandlerException {
StringWriter writer = new StringWriter();
RDFWriter nTriplesWriter = new NTriplesWriter(writer);
nTriplesWriter.startRDF();
for (Statement nextStatement : statements) {
nTriplesWriter.handleStatement(nextStatement);
}
nTriplesWriter.endRDF();
return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class TestTurtleParser method testParseDots.
@Test
public void testParseDots() throws Exception {
String data = prefixes + " ex:foo.bar ex:\\~foo.bar ex:foobar. ";
parser.parse(new StringReader(data), baseURI);
assertTrue(errorCollector.getWarnings().isEmpty());
assertTrue(errorCollector.getErrors().isEmpty());
assertTrue(errorCollector.getFatalErrors().isEmpty());
assertFalse(statementCollector.getStatements().isEmpty());
assertEquals(1, statementCollector.getStatements().size());
for (Statement st : statementCollector.getStatements()) {
System.out.println(st);
}
}
Aggregations