/** * Extracts data from the parent of ontClass that is a {@link Restriction} of type * {@link com.hp.hpl.jena.ontology.HasValueRestriction}. Updates the {@link SolrInputDocument} for ontClass. * * @param doc the input Solr document * @param restriction the restriction */ private void extractHasValueRestriction(@Nonnull final SolrInputDocument doc, @Nonnull final Restriction restriction) { // Not all of these have pretty names. Re-map these via managed-schema.xml field configurations. final String fieldName = getOnPropertyFromRestriction(restriction); final String fieldValue = restriction.asHasValueRestriction().getHasValue().asLiteral().getLexicalForm(); if (StringUtils.isNotBlank(fieldName) && StringUtils.isNotBlank(fieldValue)) { if (!this.isIntersection) { addMultivaluedField(doc, fieldName, fieldValue); } else { writeWorldwideDataFromRestriction(doc, fieldName, fieldValue); } } else { this.logger.warn("Could not extract data from hasValue restriction {}, onProperty {}, in class {}", restriction.getId(), fieldName, doc.getFieldValue(ID_FIELD_NAME)); } }
/** * Extracts data from the parent of ontClass that is a {@link Restriction} and updates the{@link SolrInputDocument} * for ontClass. * * @param doc the Solr input document * @param parent the parent class that contains restriction data for the ontologyClass */ private void extractRestrictionData(@Nonnull final SolrInputDocument doc, @Nonnull final OntClass parent) { final Restriction restriction = parent.asRestriction(); // Restrictions can be someValuesFrom, hasValue, allValuesFrom, etc. ORDO appears to only use the first two. if (restriction.isSomeValuesFromRestriction()) { extractSomeValuesFromRestriction(doc, restriction); } else if (restriction.isHasValueRestriction()) { extractHasValueRestriction(doc, restriction); } else { this.logger .warn("Restriction {} in class {} is neither someValuesFrom nor hasValue type.", restriction.getId(), doc.getFieldValue(ID_FIELD_NAME)); } }
private void preprocessRestriction(Restriction restriction) { OntProperty ontProperty = restriction.getOnProperty(); Set<PropertyEditor> propertyEditors = propertyToEditorMap.get( ontProperty.getLocalName()); ontProperty.getLocalName()); ExtendedIterator iterator = restriction.listSubClasses(true); while (iterator.hasNext()) { OntClass ontClass = (OntClass) iterator.next(); if (restriction.isAllValuesFromRestriction()) { AllValuesFromRestriction valuesFromRestriction = restriction.asAllValuesFromRestriction(); if (propertyEditor instanceof ObjectPropertyEditor) { OntClass values = (OntClass) valuesFromRestriction.
/** * <p>Answer a class description defined as the class of those individuals that have at least * one property with a value belonging to the given class</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param cls The class to which at least one value of the property belongs * @return A new resource representing a some-values-from restriction */ @Override public SomeValuesFromRestriction createSomeValuesFromRestriction( String uri, Property prop, Resource cls ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); if (prop == null || cls == null) { throw new IllegalArgumentException( "Cannot create someValuesFromRestriction with a null property or class" ); } checkProfileEntry( getProfile().SOME_VALUES_FROM(), "SOME_VALUES_FROM" ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().SOME_VALUES_FROM(), cls ); return r.as( SomeValuesFromRestriction.class ); }
/** * A workaround to obtain the label for the onProperty field for a {@link Restriction}. Ideally, this should be done * by using the {@link Restriction#onProperty(Property)}, however for ORDO, the stored node cannot be converted into * an OntProperty class. * * @param restriction the restriction being examined * @return the onProperty label as a string */ private String getOnPropertyFromRestriction(@Nonnull final Restriction restriction) { final ExtendedIterator<Statement> statements = restriction.listProperties(); while (statements.hasNext()) { final Statement statement = statements.next(); // Workaround for getting the property label. if (ON_PROPERTY_LABEL.equals(statement.getPredicate().getLocalName())) { final String onPropertyLink = statement.getObject().toString(); return restriction.getOntModel().getOntResource(onPropertyLink).getLabel(null); } } statements.close(); return null; }
/** * Obtains the label for the {@link Restriction} of type {@link com.hp.hpl.jena.ontology.SomeValuesFromRestriction}. * * @param restriction the restriction being examined * @return the someValuesFrom restriction value as a string */ private String getSomeValuesFromRestriction(@Nonnull final Restriction restriction) { final OntClass ontClass = restriction.asSomeValuesFromRestriction().getSomeValuesFrom().as(OntClass.class); return !hasHierarchyRootAsParent(ontClass, !DIRECT) ? ontClass.getLabel(null) : getFormattedOntClassId(ontClass.getLocalName()); }
/** * Extracts data from the parent of ontClass that is a {@link Restriction} of type * {@link com.hp.hpl.jena.ontology.SomeValuesFromRestriction}. Updates the {@link SolrInputDocument} for ontClass. * * @param doc the input Solr document * @param restriction the restriction */ private void extractSomeValuesFromRestriction(@Nonnull final SolrInputDocument doc, @Nonnull final Restriction restriction) { // someValuesFrom restrictions refer to the other "modifier" classes such as inheritance, geography, etc. // If a disease is part of a group of disorders, it will also be indicated here under a "part_of" property. final String fieldName = getOnPropertyFromRestriction(restriction); final String fieldValue = getSomeValuesFromRestriction(restriction); if (StringUtils.isNotBlank(fieldName) && StringUtils.isNotBlank(fieldValue)) { if ("present_in".equals(fieldName)) { this.region = fieldValue; addMultivaluedField(doc, fieldName, fieldValue); return; } if (!this.isIntersection) { addMultivaluedField(doc, fieldName, fieldValue); } else { writeWorldwideDataFromRestriction(doc, fieldName, fieldValue); } } else { this.logger.warn("Could not extract data from someValuesFrom restriction {}, onProperty {}, in class {}", restriction.getId(), fieldName, doc.getFieldValue(ID_FIELD_NAME)); } }
if (!ignore.contains(restriction)) { OwlUtils.listRestrictions(clazz); OntProperty property = restriction.getOnProperty(); OntClass restrictionClass = OwlUtils.getValuesFromAsClass(restriction); if (restrictionClass != null) {
/** * <p>Answer a class description defined as the class of those individuals for which all values * of the given property belong to the given class</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param cls The class to which any value of the property belongs * @return A new resource representing an all-values-from restriction */ @Override public AllValuesFromRestriction createAllValuesFromRestriction( String uri, Property prop, Resource cls ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); if (prop == null || cls == null) { throw new IllegalArgumentException( "Cannot create allValuesFromRestriction with a null property or class" ); } checkProfileEntry( getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM" ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().ALL_VALUES_FROM(), cls ); return r.as( AllValuesFromRestriction.class ); }
/** * A workaround to obtain the label for the onProperty field for a {@link Restriction}. Ideally, this should be done * by using the {@link Restriction#onProperty(Property)}, however for Orphanet, the stored node cannot be converted * into an OntProperty class. * * @param restriction the restriction being examined * @return the onProperty label as a string */ private String getOnPropertyFromRestriction(@Nonnull final Restriction restriction) { final ExtendedIterator<Statement> statements = restriction.listProperties(); while (statements.hasNext()) { final Statement statement = statements.next(); // Workaround for getting the property label. if (ON_PROPERTY_LABEL.equals(statement.getPredicate().getLocalName())) { final String onPropertyLink = statement.getObject().toString(); return restriction.getOntModel().getOntResource(onPropertyLink).getLabel(null); } } statements.close(); return null; }
/** * Obtains the label for the {@link Restriction} of type {@link com.hp.hpl.jena.ontology.SomeValuesFromRestriction}. * * @param restriction the restriction being examined * @return the someValuesFrom restriction value as a string */ private String getSomeValuesFromRestriction(@Nonnull final Restriction restriction) { final OntClass ontClass = restriction.asSomeValuesFromRestriction().getSomeValuesFrom().as(OntClass.class); return !hasHierarchyRootAsParent(ontClass, !DIRECT) ? ontClass.getLabel(null) : getFormattedOntClassId(ontClass.getLocalName()); }
/** * Extracts data from the parent of ontClass that is a {@link Restriction} of type * {@link com.hp.hpl.jena.ontology.SomeValuesFromRestriction}. Updates the {@link SolrInputDocument} for ontClass. * * @param doc the input Solr document * @param restriction the restriction */ private void extractSomeValuesFromRestriction(@Nonnull final SolrInputDocument doc, @Nonnull final Restriction restriction) { // someValuesFrom restrictions refer to the other "modifier" classes such as inheritance, geography, etc. // If a disease is part of a group of disorders, it will also be indicated here under a "part_of" property. final String fieldName = getOnPropertyFromRestriction(restriction); final String fieldValue = getSomeValuesFromRestriction(restriction); if (StringUtils.isNotBlank(fieldName) && StringUtils.isNotBlank(fieldValue)) { if ("present_in".equals(fieldName)) { this.region = fieldValue; addMultivaluedField(doc, fieldName, fieldValue); return; } if (!this.isIntersection) { addMultivaluedField(doc, fieldName, fieldValue); } else { writeWorldwideDataFromRestriction(doc, fieldName, fieldValue); } } else { this.logger.warn("Could not extract data from someValuesFrom restriction {}, onProperty {}, in class {}", restriction.getId(), fieldName, doc.getFieldValue(ID_FIELD_NAME)); } }
/** * Extracts data from the parent of ontClass that is a {@link Restriction} and updates the{@link SolrInputDocument} * for ontClass. * * @param doc the Solr input document * @param parent the parent class that contains restriction data for the ontologyClass */ private void extractRestrictionData(@Nonnull final SolrInputDocument doc, @Nonnull final OntClass parent) { final Restriction restriction = parent.asRestriction(); // Restrictions can be someValuesFrom, hasValue, allValuesFrom, etc. Orphanet appears to only use the first two. if (restriction.isSomeValuesFromRestriction()) { extractSomeValuesFromRestriction(doc, restriction); } else if (restriction.isHasValueRestriction()) { extractHasValueRestriction(doc, restriction); } else { this.logger .warn("Restriction {} in class {} is neither someValuesFrom nor hasValue type.", restriction.getId(), doc.getFieldValue(ID_FIELD_NAME)); } }
/** * <p>Answer a class description defined as the class of those individuals that have at least * the given number of values for the given property.</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param cardinality The minimum cardinality of the property * @return A new resource representing a min-cardinality restriction */ @Override public MinCardinalityRestriction createMinCardinalityRestriction( String uri, Property prop, int cardinality ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); if (prop == null) { throw new IllegalArgumentException( "Cannot create minCardinalityRestriction with a null property" ); } checkProfileEntry( getProfile().MIN_CARDINALITY(), "MIN_CARDINALITY" ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().MIN_CARDINALITY(), createTypedLiteral( cardinality ) ); return r.as( MinCardinalityRestriction.class ); }
/** * Extracts data from the parent of ontClass that is a {@link Restriction} of type * {@link com.hp.hpl.jena.ontology.HasValueRestriction}. Updates the {@link SolrInputDocument} for ontClass. * * @param doc the input Solr document * @param restriction the restriction */ private void extractHasValueRestriction(@Nonnull final SolrInputDocument doc, @Nonnull final Restriction restriction) { // Not all of these have pretty names. Re-map these via managed-schema.xml field configurations. final String fieldName = getOnPropertyFromRestriction(restriction); final String fieldValue = restriction.asHasValueRestriction().getHasValue().asLiteral().getLexicalForm(); if (StringUtils.isNotBlank(fieldName) && StringUtils.isNotBlank(fieldValue)) { if (!this.isIntersection) { addMultivaluedField(doc, fieldName, fieldValue); } else { writeWorldwideDataFromRestriction(doc, fieldName, fieldValue); } } else { this.logger.warn("Could not extract data from hasValue restriction {}, onProperty {}, in class {}", restriction.getId(), fieldName, doc.getFieldValue(ID_FIELD_NAME)); } }
/** * <p>Answer a class description defined as the class of those individuals that have the given * resource as the value of the given property</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param value The value of the property, as a resource or RDF literal * @return A new resource representing a has-value restriction */ @Override public HasValueRestriction createHasValueRestriction( String uri, Property prop, RDFNode value ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); if (prop == null || value == null) { throw new IllegalArgumentException( "Cannot create hasValueRestriction with a null property or value" ); } checkProfileEntry( getProfile().HAS_VALUE(), "HAS_VALUE" ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().HAS_VALUE(), value ); return r.as( HasValueRestriction.class ); }
/** * <p>Answer a class description defined as the class of those individuals that have exactly * the given number of values for the given property.</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param cardinality The exact cardinality of the property * @return A new resource representing a has-value restriction */ @Override public CardinalityRestriction createCardinalityRestriction( String uri, Property prop, int cardinality ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); if (prop == null) { throw new IllegalArgumentException( "Cannot create cardinalityRestriction with a null property" ); } checkProfileEntry( getProfile().CARDINALITY(), "CARDINALITY" ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().CARDINALITY(), createTypedLiteral( cardinality ) ); return r.as( CardinalityRestriction.class ); }
/** * <p>Answer a class description defined as the class of those individuals that have at most * the given number of values for the given property.</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param cardinality The maximum cardinality of the property * @return A new resource representing a mas-cardinality restriction */ @Override public MaxCardinalityRestriction createMaxCardinalityRestriction( String uri, Property prop, int cardinality ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); if (prop == null) { throw new IllegalArgumentException( "Cannot create maxCardinalityRestriction with a null property" ); } checkProfileEntry( getProfile().MAX_CARDINALITY(), "MAX_CARDINALITY" ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().MAX_CARDINALITY(), createTypedLiteral( cardinality ) ); return r.as( MaxCardinalityRestriction.class ); }
/** * <p>Answer a class description defined as the class of those individuals that have at least * the given number of values for the given property, all values of which belong to the given * class.</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param cardinality The minimun cardinality of the property * @param cls The class to which all values of the restricted property should belong * @return A new resource representing a mas-cardinality restriction */ @Override public MinCardinalityQRestriction createMinCardinalityQRestriction( String uri, Property prop, int cardinality, OntClass cls ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); checkProfileEntry( getProfile().ON_PROPERTY(), "ON_PROPERTY" ); checkProfileEntry( getProfile().MIN_CARDINALITY_Q(), "MIN_CARDINALITY_Q" ); checkProfileEntry( getProfile().HAS_CLASS_Q(), "HAS_CLASS_Q" ); if (prop == null) { throw new IllegalArgumentException( "Cannot create MinCardinalityQRestriction with a null property" ); } if (cls == null) { throw new IllegalArgumentException( "Cannot create MinCardinalityQRestriction with a null class" ); } Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().MIN_CARDINALITY_Q(), createTypedLiteral( cardinality ) ); r.addProperty( getProfile().HAS_CLASS_Q(), cls ); return r.as( MinCardinalityQRestriction.class ); }
/** * <p>Answer a class description defined as the class of those individuals that have at most * the given number of values for the given property, all values of which belong to the given * class.</p> * * @param uri The optional URI for the restriction, or null for an anonymous restriction (which * should be the normal case) * @param prop The property the restriction applies to * @param cardinality The maximum cardinality of the property * @param cls The class to which all values of the restricted property should belong * @return A new resource representing a mas-cardinality restriction */ @Override public MaxCardinalityQRestriction createMaxCardinalityQRestriction( String uri, Property prop, int cardinality, OntClass cls ) { checkProfileEntry( getProfile().RESTRICTION(), "RESTRICTION" ); checkProfileEntry( getProfile().ON_PROPERTY(), "ON_PROPERTY" ); checkProfileEntry( getProfile().MAX_CARDINALITY_Q(), "MAX_CARDINALITY_Q" ); checkProfileEntry( getProfile().HAS_CLASS_Q(), "HAS_CLASS_Q" ); if (prop == null) { throw new IllegalArgumentException( "Cannot create MaxCardinalityQRestriction with a null property" ); } if (cls == null) { throw new IllegalArgumentException( "Cannot create MaxCardinalityQRestriction with a null class" ); } Restriction r = createOntResource( Restriction.class, getProfile().RESTRICTION(), uri ); r.addProperty( getProfile().ON_PROPERTY(), prop ); r.addProperty( getProfile().MAX_CARDINALITY_Q(), createTypedLiteral( cardinality ) ); r.addProperty( getProfile().HAS_CLASS_Q(), cls ); return r.as( MaxCardinalityQRestriction.class ); }