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;
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations