org.nlp2rdf.nif20.impl.NIF20Properties Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nif Show documentation
Show all versions of nif Show documentation
A small library for NLP Interchange Format (NIF) — Edit
The newest version!
package org.nlp2rdf.nif20.impl;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDF;
import org.nlp2rdf.NIFProperties;
import org.nlp2rdf.NIFVisitor;
import org.nlp2rdf.bean.NIFBean;
import org.nlp2rdf.nif20.NIF20Format;
public class NIF20Properties implements NIFProperties, NIF20Format {
public void add(Model model, NIFBean entity) {
if (model != null && entity != null) {
Resource contextRes = model.getResource(entity.getContext().getNIF20());
if (entity.isMention()) {
fillMention(model, entity, contextRes);
} else if (entity.isContext()) {
fillContext(model, contextRes);
}
}
}
private void fillContext(Model model, Resource contextRes) {
contextRes.addProperty(
RDF.type,
model.createResource(NIF_PROPERTY_STRING));
contextRes.addProperty(
RDF.type,
model.createResource(NIF_PROPERTY_CONTEXT));
contextRes.addProperty(
RDF.type,
model.createResource(NIF_PROPERTY_RFC5147));
}
private void fillMention(Model model, NIFBean entity, Resource contextRes) {
contextRes.addProperty(
RDF.type,
model.createResource(NIF_PROPERTY_STRING));
contextRes.addProperty(
model.createProperty(NIF_PROPERTY_REFERENCE_CONTEXT),
model.createResource(entity.getReferenceContext()));
if (entity.hasTaIdentRef()) {
contextRes.addProperty(
model.createProperty(RDF_PROPERTY_IDENTREF),
model.createResource(entity.getTaIdentRef()));
}
if (entity.hasTypes()) {
for (String type : entity.getTypes()) {
contextRes.addProperty(
model.createProperty(RDF_PROPERTY_CLASS_REF),
model.createResource(type));
}
}
contextRes.addProperty(
RDF.type,
model.createResource(NIF_PROPERTY_WORD));
contextRes.addProperty(
RDF.type,
model.createResource(NIF_PROPERTY_PHRASE));
contextRes.addProperty(
RDF.type,
model.createResource(NIF_PROPERTY_RFC5147));
}
public void accept(NIFVisitor visitor) {
visitor.visit(this);
}
}