public Collection<OntView> getCandidates() { OntResource r = verb.getRange(); r = m().getOntClass(r.getURI()); return new each(r.asClass().listInstances()) { void $() { if (!m().contains(subject, verb, item)) add(OntView.$(item)); } }.result; }
/** * Call this method to convert a value (v) as a Java object to a typed Literal matching the range * of the property. * * @param m * @param prop * @param v * @return * @throws Exception */ public static synchronized Literal getLiteralMatchingDataPropertyRange( OntModel m, OntProperty prop, Object v) throws Exception { Literal val = null; String errMsg = null; if (prop.isAnnotationProperty()) { return m.createTypedLiteral(v); } // SADL only has DoubleLiterals--if this property has range float convert v to Float. OntResource rng = prop.getRange(); String rnguri = rng != null ? rng.getURI() : null; if (rng == null) { errMsg = "Range not given."; } else if (rng.isAnon()) { // this is a complex range--needs work. Try to do something with it.... // If value is a String if (v instanceof String) { v = stripQuotes((String) v); val = m.createTypedLiteral(v); } else { val = m.createTypedLiteral(v); if (val == null) { errMsg = "Range is an unsupported complex type, failed to create a Literal value for '" + v.toString() + "'."; } } } else { val = getLiteralMatchingDataPropertyRange(m, rnguri, v); } if (errMsg != null) { errMsg += " (Property is '" + prop.getLocalName() + "'.)"; throw new Exception(errMsg); } return val; }
private void addField(OntResource type, OntProperty p, OntProperty ancestor) { int minCardinality = 0; int maxCardinality = -1; OntResource range = null; String typeURI = type.getURI(); if (typeURI == null) { // We only add fields to named types. return; } // Do not add abstract properties. if (isAbstract(p)) return; Frame frame = manager.getFrameByUri(typeURI); if (frame == null) { if (isStandard(typeURI)) return; logger.warn( "Ignoring property " + p.getLocalName() + " on class " + type.getLocalName() + ": frame not found"); return; } if (frame.getDeclaredFieldByPropertyURI(p.getURI()) != null) return; if (p.hasRDFType(OWL.FunctionalProperty)) { maxCardinality = 1; } OntClass restriction = frame.getRestriction(p.getURI()); range = p.getRange(); if (range == null && ancestor != null) { range = ancestor.getRange(); } if (range == null) { // logger.warn("Ignoring property " + p.getLocalName() + " on class " + // type.getLocalName() + ": range not defined"); // return; range = THING; } if (restriction != null) { Resource onClass = restriction.getPropertyResourceValue(OWL2.onClass); if (onClass != null) { range = onClass.as(OntResource.class); if (restriction.hasProperty(OWL2.minQualifiedCardinality)) { minCardinality = restriction.getProperty(OWL2.minQualifiedCardinality).getInt(); } if (restriction.hasProperty(OWL2.maxQualifiedCardinality)) { maxCardinality = restriction.getProperty(OWL2.maxQualifiedCardinality).getInt(); } } else { if (restriction.hasProperty(OWL.minCardinality)) { minCardinality = restriction.getProperty(OWL.minCardinality).getInt(); } if (restriction.hasProperty(OWL.maxCardinality)) { maxCardinality = restriction.getProperty(OWL.maxCardinality).getInt(); } } } Field field = null; String rangeURI = range.getURI(); if (rangeURI == null) { field = createListField(frame, p, range); if (field == null) { logger.warn( "Ignoring property " + p.getLocalName() + " on class " + type.getLocalName() + ": range has no URI"); return; } } else { field = new Field(frame, p, range, minCardinality, maxCardinality); if (field.getRdfType() == null) { logger.warn( "Failed to create RdfType for field " + field.getLocalName() + " of type " + field.getType().getURI()); } } Resource rawInverse = p.getPropertyResourceValue(OWL.inverseOf); if (rawInverse != null && rawInverse.canAs(OntProperty.class)) { field.setInverseOf(rawInverse.as(OntProperty.class)); } frame.getDeclaredFields().add(field); }