Commit 3041a75c authored by Günter Hipler's avatar Günter Hipler
Browse files

first version with probabably correct EDM prefix:type tags - no default rdf:description

parent 909a6414
Pipeline #21024 failed with stages
in 7 minutes and 18 seconds
......@@ -31,12 +31,17 @@ public class RdfXmlWriter extends RDFXMLWriter {
super(writer, baseIRI);
}
String lastWrittenSubjectNamespace = "";
String getLastWrittenSubjectPrefix = "";
@Override
protected void consumeStatement(Statement st) {
Resource subj = st.getSubject();
IRI pred = st.getPredicate();
Value obj = st.getObject();
// Verify that an XML namespace-qualified name can be created for the
// predicate
String predString = pred.toString();
......@@ -59,7 +64,17 @@ public class RdfXmlWriter extends RDFXMLWriter {
// Write new subject:
writeNewLine();
writeStartOfStartTag(RDF.NAMESPACE, "Description");
if (st.getPredicate().getLocalName().equalsIgnoreCase("type")) {
int indexSeperatorNsPrefix = st.getObject().stringValue().lastIndexOf("/");
lastWrittenSubjectNamespace = st.getObject().stringValue().substring(0,indexSeperatorNsPrefix+1);
getLastWrittenSubjectPrefix = st.getObject().stringValue().substring(indexSeperatorNsPrefix+1);
writeStartOfStartTag(lastWrittenSubjectNamespace, getLastWrittenSubjectPrefix);
} else {
writeStartOfStartTag(RDF.NAMESPACE, "Description");
}
if (subj instanceof BNode) {
BNode bNode = (BNode) subj;
writeAttribute(RDF.NAMESPACE, "nodeID", getValidNodeId(bNode));
......@@ -136,4 +151,28 @@ public class RdfXmlWriter extends RDFXMLWriter {
}
}
@Override
protected void flushPendingStatements() throws IOException, RDFHandlerException {
if (lastWrittenSubject != null) {
// The last statement still has to be closed:
//if we have written the last suubject in "EDM style" (direct use of prefix and namespace)
//we have to close the tag in the same way.
if (lastWrittenSubjectNamespace.length() > 0 && getLastWrittenSubjectPrefix.length() > 0) {
writeEndTag(lastWrittenSubjectNamespace, getLastWrittenSubjectPrefix);
lastWrittenSubjectNamespace = "";
getLastWrittenSubjectPrefix = "";
} else {
writeEndTag(RDF.NAMESPACE, "Description");
}
writeNewLine();
lastWrittenSubject = null;
}
}
}
......@@ -25,7 +25,7 @@ import ch.memobase.rdf.Helper
import ch.memobase.rdf.vocabularies.EDM
import org.eclipse.rdf4j.model.Model
import org.eclipse.rdf4j.model.impl.{DynamicModelFactory, SimpleValueFactory}
import org.eclipse.rdf4j.model.vocabulary.{DCTERMS, RDF}
import org.eclipse.rdf4j.model.vocabulary.{DC, DCTERMS, RDF}
import java.time.format.DateTimeFormatter
import scala.collection.mutable
......@@ -94,6 +94,7 @@ class ProvidedCHO {
model.add(iri(_id),RDF.TYPE, EDM.ProvidedCHO)
//only for test purposes by now
model.add(iri(_id),DCTERMS.ISSUED,factory.createLiteral("1993"))
model.add(iri(_id),DC.CONTRIBUTOR, factory.createLiteral("Günter Hipler"))
model
}
......
......@@ -33,5 +33,6 @@ object EDM extends VocabularyFactory("http://www.europeana.eu/schemas/edm/") {
val ProvidedCHO: IRI = getIri("ProvidedCHO")
}
<rdf:RDF
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:edm="http://www.europeana.eu/schemas/edm/"
xmlns:ore="http://www.openarchives.org/ore/terms/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:wgs84_pos="http://www.w3.org/2004/02/skos/core#"
xmlns:crm="http://www.cidoc‐crm.org/cidoc‐crm/"
xmlns:cc="http://creativecommons.org/ns#">
<edm:ProvidedCHO rdf:about="https://memobase.ch/record/ati-001-L_44_13">
<rdf:type rdf:resource="http://www.europeana.eu/schemas/edm/ProvidedCHO"/>
<dcterms:issued>1993</dcterms:issued>
<dc:contributor>Günter Hipler</dc:contributor>
</edm:ProvidedCHO>
</rdf:RDF>
/*
* rico2edm
* Copyright (C) 2021 UB Basel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
package ch.memobase.edm
import ch.memobase.rdf.writer.RdfXmlWriter
import org.eclipse.rdf4j.rio.{RDFFormat, RDFWriter, Rio}
import org.scalatest.funsuite.AnyFunSuite
import java.io.StringReader
class RdfXmlWriterSpec extends AnyFunSuite{
import ch.memobase.Utils._
test("read result created by own RdfXmlWriter and write again with writer") {
val rdfParser = Rio.createParser(RDFFormat.RDFXML);
//val rdfWriter: RDFWriter = Rio.createWriter(RDFFormat.RDFXML, System.out)
val rdfWriter = new RdfXmlWriter(System.out)
rdfParser.setRDFHandler(rdfWriter)
rdfParser.parse(new StringReader(loadFile("src/test/resources/edm.own.rdf.writer.xml")),"")
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment