Search in sources :

Example 1 with SimpleSelector

use of com.hp.hpl.jena.rdf.model.SimpleSelector in project ambit-mirror by ideaconsult.

the class RDFIteratingReader method initIterator.

private StmtIterator initIterator() {
    if (recordIterator == null) {
        Resource s = OT.OTClass.DataEntry.getOntClass(jenaModel);
        if (s == null)
            return null;
        recordIterator = jenaModel.listStatements(new SimpleSelector(null, RDF.type, s));
    }
    return recordIterator;
}
Also used : SimpleSelector(com.hp.hpl.jena.rdf.model.SimpleSelector) Resource(com.hp.hpl.jena.rdf.model.Resource)

Example 2 with SimpleSelector

use of com.hp.hpl.jena.rdf.model.SimpleSelector in project ambit-mirror by ideaconsult.

the class RDFInstancesIterator method parseFeatureValues.

@Override
protected void parseFeatureValues(Resource dataEntry, Instance record) {
    StmtIterator values = jenaModel.listStatements(new SimpleSelector(dataEntry, OT.OTProperty.values.createProperty(jenaModel), (RDFNode) null));
    while (values.hasNext()) {
        Statement st = values.next();
        if (st.getObject().isResource()) {
            Resource fv = (Resource) st.getObject();
            Statement st1 = fv.getProperty(OT.DataProperty.value.createProperty(jenaModel));
            if (st1 == null)
                continue;
            RDFNode value = st1.getObject();
            if (value == null)
                continue;
            RDFNode feature = fv.getProperty(OT.OTProperty.feature.createProperty(jenaModel)).getObject();
            Attribute key = urilookup.get(feature.toString());
            if (key != null)
                setFeatureValue(record, key, value);
        }
    }
}
Also used : StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) SimpleSelector(com.hp.hpl.jena.rdf.model.SimpleSelector) Attribute(weka.core.Attribute) Statement(com.hp.hpl.jena.rdf.model.Statement) Resource(com.hp.hpl.jena.rdf.model.Resource) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode)

Example 3 with SimpleSelector

use of com.hp.hpl.jena.rdf.model.SimpleSelector in project ambit-mirror by ideaconsult.

the class RDFInstancesIterator method parseFeatures.

protected FastVector parseFeatures() {
    FastVector attributes = new FastVector();
    Attribute id = new Attribute(CompoundURI, (FastVector) null);
    urilookup.put(CompoundURI, id);
    attributes.addElement(id);
    Resource s = OT.OTClass.Feature.getOntClass(jenaModel);
    if (s == null)
        return null;
    Property valueProperty = OT.DataProperty.value.createProperty(jenaModel);
    Property featureProperty = OT.OTProperty.feature.createProperty(jenaModel);
    Resource nominalFeatureClass = OT.OTClass.NominalFeature.getOntClass(jenaModel);
    StmtIterator features = jenaModel.listStatements(new SimpleSelector(null, RDF.type, s));
    while (features.hasNext()) {
        Statement feature = features.next();
        boolean isNominal = false;
        // check if nominal
        StmtIterator nominalFeatures = jenaModel.listStatements(new SimpleSelector(feature.getSubject(), RDF.type, nominalFeatureClass));
        while (nominalFeatures.hasNext()) {
            nominalFeatures.next();
            isNominal = true;
            break;
        }
        nominalFeatures.close();
        int ndouble = 0;
        int nstring = 0;
        FastVector nominal = new FastVector();
        StmtIterator entries = jenaModel.listStatements(new SimpleSelector(null, featureProperty, feature.getSubject()));
        while (entries.hasNext()) {
            isNominal = false;
            Resource entry = entries.next().getSubject();
            try {
                Statement values = entry.getProperty(valueProperty);
                if (values.getObject().isLiteral()) {
                    Class clazz = ((Literal) values.getObject()).getDatatype().getJavaClass();
                    if (!isNominal) {
                        if (clazz == Double.class)
                            ndouble++;
                        else if (clazz == Float.class)
                            ndouble++;
                        else if (clazz == Integer.class)
                            ndouble++;
                        else if (clazz == Long.class)
                            ndouble++;
                        else if (clazz == Short.class)
                            ndouble++;
                        else
                            // strings become nominals,
                            isNominal = true;
                    // even if not declared as
                    // such
                    }
                    if (isNominal) {
                        String value = ((Literal) values.getObject()).getString();
                        if ((nominal.size() < (maxNominalValues + 1)) && !nominal.contains(value))
                            nominal.addElement(value);
                        nstring++;
                    }
                }
            } catch (Exception x) {
                x.printStackTrace();
            }
        }
        entries.close();
        if ((ndouble + nstring) == 0)
            continue;
        Attribute a = null;
        if (// numeric feature
        ndouble > nstring)
            a = new Attribute(feature.getSubject().toString());
        else if (// string attribute
        nominal.size() > maxNominalValues)
            a = new Attribute(feature.getSubject().toString(), (FastVector) null);
        else
            a = new Attribute(feature.getSubject().toString(), nominal);
        urilookup.put(feature.getSubject().toString(), a);
        attributes.addElement(a);
    }
    return attributes;
}
Also used : StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) SimpleSelector(com.hp.hpl.jena.rdf.model.SimpleSelector) FastVector(weka.core.FastVector) Attribute(weka.core.Attribute) Statement(com.hp.hpl.jena.rdf.model.Statement) Resource(com.hp.hpl.jena.rdf.model.Resource) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ResourceException(org.restlet.resource.ResourceException) Literal(com.hp.hpl.jena.rdf.model.Literal) OTClass(net.idea.restnet.rdf.ns.OT.OTClass) Property(com.hp.hpl.jena.rdf.model.Property)

Example 4 with SimpleSelector

use of com.hp.hpl.jena.rdf.model.SimpleSelector in project ambit-mirror by ideaconsult.

the class RDFInstancesIterator method parseRecord.

@Override
protected Instance parseRecord(RDFNode newEntry, Instance record) {
    if (newEntry.isLiteral())
        return record;
    String id = null;
    // get the compound
    StmtIterator compound = jenaModel.listStatements(new SimpleSelector((Resource) newEntry, OT.OTProperty.compound.createProperty(jenaModel), (RDFNode) null));
    while (compound.hasNext()) {
        Statement st = compound.next();
        id = st.getObject().toString();
        break;
    }
    try {
        record.setValue(urilookup.get(CompoundURI), id);
    } catch (Exception x) {
        x.printStackTrace();
    }
    // get feature values
    parseFeatureValues((Resource) newEntry, record);
    record.setDataset(instances);
    instances.add(record);
    return record;
}
Also used : StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) SimpleSelector(com.hp.hpl.jena.rdf.model.SimpleSelector) Statement(com.hp.hpl.jena.rdf.model.Statement) Resource(com.hp.hpl.jena.rdf.model.Resource) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ResourceException(org.restlet.resource.ResourceException)

Example 5 with SimpleSelector

use of com.hp.hpl.jena.rdf.model.SimpleSelector in project ambit-mirror by ideaconsult.

the class OTFeature method setSameas.

public OTFeature setSameas(String newLabel) throws Exception {
    Model jenaModel = ModelFactory.createDefaultModel();
    jenaModel.setNsPrefix("ot", OT.NS);
    jenaModel.setNsPrefix("ota", OTA.NS);
    jenaModel.setNsPrefix("otee", OTEE.NS);
    jenaModel.setNsPrefix("owl", OWL.NS);
    jenaModel.setNsPrefix("dc", DC.NS);
    jenaModel.setNsPrefix("bx", BibTex.NS);
    jenaModel.setNsPrefix("xsd", XSDDatatype.XSD + "#");
    jenaModel = OT.createModel(jenaModel, getUri(), MediaType.APPLICATION_RDF_XML, referer);
    Resource thisFeature = jenaModel.createResource(getUri().toString());
    StmtIterator i = jenaModel.listStatements(new SimpleSelector(thisFeature, OWL.sameAs, (RDFNode) null));
    Statement st = null;
    while (i.hasNext()) {
        st = i.next();
        break;
    }
    i.close();
    if (st != null)
        jenaModel.remove(st);
    jenaModel.add(thisFeature, OWL.sameAs, newLabel);
    put(jenaModel);
    jenaModel.close();
    return this;
}
Also used : StmtIterator(com.hp.hpl.jena.rdf.model.StmtIterator) SimpleSelector(com.hp.hpl.jena.rdf.model.SimpleSelector) Statement(com.hp.hpl.jena.rdf.model.Statement) Model(com.hp.hpl.jena.rdf.model.Model) OntModel(com.hp.hpl.jena.ontology.OntModel) Resource(com.hp.hpl.jena.rdf.model.Resource) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode)

Aggregations

SimpleSelector (com.hp.hpl.jena.rdf.model.SimpleSelector)16 Resource (com.hp.hpl.jena.rdf.model.Resource)14 Statement (com.hp.hpl.jena.rdf.model.Statement)14 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)14 RDFNode (com.hp.hpl.jena.rdf.model.RDFNode)13 Literal (com.hp.hpl.jena.rdf.model.Literal)5 ResourceException (org.restlet.resource.ResourceException)5 Property (ambit2.base.data.Property)4 IOException (java.io.IOException)4 MalformedURLException (java.net.MalformedURLException)3 Reference (org.restlet.data.Reference)3 OntModel (com.hp.hpl.jena.ontology.OntModel)2 Model (com.hp.hpl.jena.rdf.model.Model)2 Property (com.hp.hpl.jena.rdf.model.Property)2 Hashtable (java.util.Hashtable)2 OTProperty (net.idea.restnet.rdf.ns.OT.OTProperty)2 Attribute (weka.core.Attribute)2 PropertyAnnotation (ambit2.base.data.PropertyAnnotation)1 PropertyAnnotations (ambit2.base.data.PropertyAnnotations)1 RDFDatatype (com.hp.hpl.jena.datatypes.RDFDatatype)1