Search in sources :

Example 1 with Literal

use of com.hp.hpl.jena.rdf.model.Literal in project lucene-skos by behas.

the class SKOSEngineImpl method indexAnnotation.

private void indexAnnotation(Resource skos_concept, Document conceptDoc, AnnotationProperty property, String field) {
    StmtIterator stmt_iter = skos_concept.listProperties(property);
    while (stmt_iter.hasNext()) {
        Literal labelLiteral = stmt_iter.nextStatement().getObject().as(Literal.class);
        String label = labelLiteral.getLexicalForm();
        String labelLang = labelLiteral.getLanguage();
        if (this.languages != null && !this.languages.isEmpty() && !this.languages.contains(labelLang)) {
            continue;
        }
        // converting label to lower-case
        label = label.toLowerCase(Locale.ROOT);
        Field labelField = new Field(field, label, StringField.TYPE_STORED);
        conceptDoc.add(labelField);
    }
}
Also used : StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) Literal(com.hp.hpl.jena.rdf.model.Literal)

Example 2 with Literal

use of com.hp.hpl.jena.rdf.model.Literal in project stanbol by apache.

the class ConversionTester method testResourceJenaToOwlAxiom.

public void testResourceJenaToOwlAxiom() {
    JenaToOwlConvert j2o = new JenaToOwlConvert();
    OntModel model = ModelFactory.createOntologyModel();
    OntClass jenaclass = model.createClass(CLAZZ.toString());
    ObjectProperty jenaobprop = model.createObjectProperty(OP.toString());
    DatatypeProperty jenadataprop = model.createDatatypeProperty(DP.toString());
    Individual jenasub = model.createIndividual(SUBJECT.toString(), jenaclass);
    Individual jenaobj = model.createIndividual(OBJECT.toString(), jenaclass);
    AnnotationProperty jenaanno = model.createAnnotationProperty(label.toString());
    Literal value = model.createTypedLiteral(VALUE, DATATYPE.toString());
    model.add(jenasub, jenaobprop, jenaobj);
    model.add(jenasub, jenadataprop, value);
    model.add(jenasub, jenaanno, "Lucy", "en");
    Set<OWLAxiom> owlaxiom = null;
    try {
        owlaxiom = j2o.ResourceJenaToOwlAxiom(jenasub, RDFXML);
        if (owlaxiom == null) {
            fail("Some errors occur");
        } else {
            StmtIterator str = model.listStatements();
            int count = 0;
            while (str.hasNext()) {
                Statement stm = str.next();
                Resource subject = stm.getSubject();
                if (SUBJECT.toString().equals(subject.getURI()))
                    count++;
            }
            if (count == owlaxiom.size()) {
                assertEquals(count, owlaxiom.size());
            } else {
                fail("The number of axioms don't match the number of statement");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception caugth");
    } finally {
        assertNotNull(owlaxiom);
    }
}
Also used : OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) ObjectProperty(com.hp.hpl.jena.ontology.ObjectProperty) StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) Statement(com.hp.hpl.jena.rdf.model.Statement) Resource(com.hp.hpl.jena.rdf.model.Resource) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) AnnotationProperty(com.hp.hpl.jena.ontology.AnnotationProperty) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) Individual(com.hp.hpl.jena.ontology.Individual) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) Literal(com.hp.hpl.jena.rdf.model.Literal) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OntClass(com.hp.hpl.jena.ontology.OntClass) DatatypeProperty(com.hp.hpl.jena.ontology.DatatypeProperty)

Aggregations

Literal (com.hp.hpl.jena.rdf.model.Literal)2 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)2 AnnotationProperty (com.hp.hpl.jena.ontology.AnnotationProperty)1 DatatypeProperty (com.hp.hpl.jena.ontology.DatatypeProperty)1 Individual (com.hp.hpl.jena.ontology.Individual)1 ObjectProperty (com.hp.hpl.jena.ontology.ObjectProperty)1 OntClass (com.hp.hpl.jena.ontology.OntClass)1 OntModel (com.hp.hpl.jena.ontology.OntModel)1 Resource (com.hp.hpl.jena.rdf.model.Resource)1 Statement (com.hp.hpl.jena.rdf.model.Statement)1 Field (org.apache.lucene.document.Field)1 StringField (org.apache.lucene.document.StringField)1 TextField (org.apache.lucene.document.TextField)1 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)1 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)1 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1