
eu.monnetproject.label.rdf.RDFLabelExtractionPolicy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontology.label Show documentation
Show all versions of ontology.label Show documentation
com.github.monnetproject.ontology.label OSGi Bundle from the Monnet Project's ontology.project project.
The newest version!
package eu.monnetproject.label.rdf;
import java.net.URI;
import java.util.*;
import eu.monnetproject.lang.Language;
import eu.monnetproject.label.LabelExtractor;
import eu.monnetproject.ontology.*;
import aQute.bnd.annotation.component.*;
@Component(provide=LabelExtractor.class)
public class RDFLabelExtractionPolicy implements LabelExtractor {
public static final URI RDFS_LABEL = URI.create("http://www.w3.org/2000/01/rdf-schema#label");
public RDFLabelExtractionPolicy() {
}
public Map> getLabels(Entity entity) {
AnnotationProperty property = null;
for (AnnotationProperty prop : entity.getAnnotations().keySet()) {
if (prop.getURI().equals(RDFS_LABEL)) {
property = prop;
}
}
if (property == null) {
return Collections.EMPTY_MAP;
}
Collection lits = entity.getAnnotationValues(property);
HashMap> rv = new HashMap>();
for (AnnotationValue av : lits) {
if (av instanceof LiteralValue) {
LiteralValue lit = (LiteralValue) av;
Language language = lit.getLanguage();
if (language == null) {
language = LabelExtractor.NO_LANGUAGE;
}
if (!rv.containsKey(language)) {
rv.put(language, new HashSet());
}
rv.get(language).add(lit.getValue());
}
}
return rv;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy