@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); OntProperty p = m.createObjectProperty( NS + "p" ); OntClass B = m.createClass( NS + "B" ); Individual b = m.createIndividual( B ); OntClass C = m.createClass( NS + "C" ); Individual c = m.createIndividual( C ); HasValueRestriction A = m.createHasValueRestriction( NS + "A", p, b ); assertEquals( "Restriction should be has value b", b, A.getHasValue() ); assertTrue( A.getHasValue() instanceof Individual ); assertTrue( "Restriction should be to have value b", A.hasValue( b ) ); assertTrue( "Restriction should not be have value c", !A.hasValue( c ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() )); A.setHasValue( c ); assertEquals( "Restriction should be has value c", c, A.getHasValue() ); assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) ); assertTrue( "Restriction should not be have value c", A.hasValue( c ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() )); A.removeHasValue( c ); assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) ); assertTrue( "Restriction should not be have value c", !A.hasValue( c ) ); assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.HAS_VALUE() )); } },
/** * Extracts data from the parent of ontClass that is a {@link Restriction} of type * {@link org.apache.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)); } }
results.add("has value"); HasValueRestriction hvrest = (HasValueRestriction) rest.as(HasValueRestriction.class); RDFNode hasValue = hvrest.getHasValue(); if (hasValue.isResource()) { Resource hasValueRes = (Resource) hasValue.as(Resource.class);
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); OntProperty p = m.createObjectProperty( NS + "p" ); OntClass B = m.createClass( NS + "B" ); Individual b = m.createIndividual( B ); OntClass C = m.createClass( NS + "C" ); Individual c = m.createIndividual( C ); HasValueRestriction A = m.createHasValueRestriction( NS + "A", p, b ); assertEquals( "Restriction should be has value b", b, A.getHasValue() ); assertTrue( A.getHasValue() instanceof Individual ); assertTrue( "Restriction should be to have value b", A.hasValue( b ) ); assertTrue( "Restriction should not be have value c", !A.hasValue( c ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() )); A.setHasValue( c ); assertEquals( "Restriction should be has value c", c, A.getHasValue() ); assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) ); assertTrue( "Restriction should not be have value c", A.hasValue( c ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() )); A.removeHasValue( c ); assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) ); assertTrue( "Restriction should not be have value c", !A.hasValue( c ) ); assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.HAS_VALUE() )); } },
HasValueRestriction hvRest = rest.asHasValueRestriction(); labelStr.append("has value "); RDFNode fillerNode = hvRest.getHasValue(); try { if (fillerNode.isResource()) {
HasValueRestriction hvRest = rest.asHasValueRestriction(); labelStr += "has value "; RDFNode fillerNode = hvRest.getHasValue(); try { if (fillerNode.isResource()) {