@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createMaxCardinalityRestriction( null, p, 5 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", a.isMaxCardinalityRestriction() ); } },
private void printRestrictions() { TBoxReasonerModule reasoner = ApplicationUtils.instance().getTBoxReasonerModule(); for (Restriction rest : reasoner.listRestrictions() ) { if (rest.isAllValuesFromRestriction()) { log.trace("All values from: "); AllValuesFromRestriction avfr = rest.asAllValuesFromRestriction(); Resource res = avfr.getAllValuesFrom(); if (res.canAs(OntClass.class)) { OntClass resClass = res.as(OntClass.class); for (Resource inst : resClass.listInstances().toList() ) { log.trace(" -"+inst.getURI()); } } } else if (rest.isSomeValuesFromRestriction()) { log.trace("Some values from: "); } else if (rest.isHasValueRestriction()) { log.trace("Has value: "); } log.trace("On property "+rest.getOnProperty().getURI()); for (Resource inst : rest.listInstances().toList() ) { log.trace(" "+inst.getURI()); } } }
/** * 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)); } }
/** * 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)); } }
try { results.add("XX"); Property onProperty = rest.getOnProperty(); ObjectProperty op = opDao.getObjectPropertyByURI(onProperty.getURI()); results.add(op.getPickListName()); if (rest.isAllValuesFromRestriction()) { results.add("all values from"); AllValuesFromRestriction avfrest = (AllValuesFromRestriction) rest.as(AllValuesFromRestriction.class); Resource allValuesFrom = avfrest.getAllValuesFrom(); results.add(printAsClass(vcDao, allValuesFrom)); } else if (rest.isSomeValuesFromRestriction()) { results.add("some values from"); SomeValuesFromRestriction svfrest = (SomeValuesFromRestriction) rest.as(SomeValuesFromRestriction.class); Resource someValuesFrom = svfrest.getSomeValuesFrom(); results.add(printAsClass(vcDao, someValuesFrom)); } else if (rest.isHasValueRestriction()) { results.add("has value"); HasValueRestriction hvrest = (HasValueRestriction) rest.as(HasValueRestriction.class); RDFNode hasValue = hvrest.getHasValue(); if (hasValue.isResource()) { } else if (rest.isMinCardinalityRestriction()) { MinCardinalityRestriction crest = (MinCardinalityRestriction) rest.as(MinCardinalityRestriction.class); results.add("at least "+crest.getMinCardinality()); results.add(LAMBDA); } else if (rest.isMaxCardinalityRestriction()) { MaxCardinalityRestriction crest = (MaxCardinalityRestriction) rest.as(MaxCardinalityRestriction.class); results.add("at most "+crest.getMaxCardinality()); results.add(LAMBDA);
if (cls.isRestriction()) { Restriction rest = cls.asRestriction(); OntProperty onProperty = rest.getOnProperty(); StringBuilder labelStr = new StringBuilder(); labelStr.append("restriction on ").append(getLabelOrId(onProperty)).append(": "); if (rest.isAllValuesFromRestriction() || rest.isSomeValuesFromRestriction()) { Resource fillerRes = null; if (rest.isAllValuesFromRestriction()) { AllValuesFromRestriction avfRest = rest.asAllValuesFromRestriction(); fillerRes = avfRest.getAllValuesFrom(); labelStr.append("all values from "); } else { SomeValuesFromRestriction svfRest = rest.asSomeValuesFromRestriction(); fillerRes = svfRest.getSomeValuesFrom(); labelStr.append("some values from "); } else if (rest.isHasValueRestriction()) { HasValueRestriction hvRest = rest.asHasValueRestriction(); labelStr.append("has value "); RDFNode fillerNode = hvRest.getHasValue(); } else if (rest.isMinCardinalityRestriction()) { MinCardinalityRestriction mcRest = rest.asMinCardinalityRestriction(); labelStr.append("minimum cardinality "); labelStr.append(mcRest.getMinCardinality()); } else if (rest.isMaxCardinalityRestriction()) { MaxCardinalityRestriction mcRest = rest.asMaxCardinalityRestriction(); labelStr.append("maximum cardinality "); labelStr.append(mcRest.getMaxCardinality());
OntProperty onProperty = rest.getOnProperty(); if (onProperty != null) { Resource[] ranges = new Resource[2]; if (rest.isAllValuesFromRestriction()) { ranges[0] = (rest.asAllValuesFromRestriction()).getAllValuesFrom(); updatePropertyRangeMap(applicableProperties, onProperty.getURI(), ranges, true); } else if (rest.isSomeValuesFromRestriction()) { ranges[1] = (rest.asSomeValuesFromRestriction()).getSomeValuesFrom(); updatePropertyRangeMap(applicableProperties, onProperty.getURI(), ranges, false);
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); OntProperty p = m.createObjectProperty( NS + "p" ); OntProperty q = m.createObjectProperty( NS + "q" ); OntClass B = m.createClass( NS + "B" ); Restriction A = m.createAllValuesFromRestriction( NS + "A", p, B ); assertEquals( "Restriction should be on property p", p, A.getOnProperty() ); assertTrue( "Restriction should be on property p", A.onProperty( p ) ); assertTrue( "Restriction should not be on property q", !A.onProperty( q ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ON_PROPERTY() )); A.setOnProperty( q ); assertEquals( "Restriction should be on property q", q, A.getOnProperty() ); assertTrue( "Restriction should not be on property p", !A.onProperty( p ) ); assertTrue( "Restriction should not on property q", A.onProperty( q ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ON_PROPERTY() )); A.removeOnProperty( p ); assertTrue( "Should have q as on property", A.onProperty( q ) ); A.removeOnProperty( q ); assertTrue( "Should not have q as on property", !A.onProperty( q ) ); } },
if (restRes.canAs(Restriction.class)) { Restriction rest = restRes.as(Restriction.class); if (rest.isAllValuesFromRestriction()) { AllValuesFromRestriction avfrest = rest.asAllValuesFromRestriction(); if (avfrest.getAllValuesFrom() != null) {
/** * Obtains the label for the {@link Restriction} of type {@link org.apache.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()); }
if (cls.isRestriction()) { Restriction rest = cls.asRestriction(); OntProperty onProperty = rest.getOnProperty(); String labelStr = "restriction on " + getLabelOrId(onProperty) + ": "; if (rest.isAllValuesFromRestriction() || rest.isSomeValuesFromRestriction()) { Resource fillerRes = null; if (rest.isAllValuesFromRestriction()) { AllValuesFromRestriction avfRest = rest.asAllValuesFromRestriction(); fillerRes = avfRest.getAllValuesFrom(); labelStr += "all values from "; } else { SomeValuesFromRestriction svfRest = rest.asSomeValuesFromRestriction(); fillerRes = svfRest.getSomeValuesFrom(); labelStr += "some values from "; } else if (rest.isHasValueRestriction()) { HasValueRestriction hvRest = rest.asHasValueRestriction(); labelStr += "has value "; RDFNode fillerNode = hvRest.getHasValue(); } else if (rest.isMinCardinalityRestriction()) { MinCardinalityRestriction mcRest = rest.asMinCardinalityRestriction(); labelStr += "minimum cardinality "; labelStr += mcRest.getMinCardinality(); } else if (rest.isMaxCardinalityRestriction()) { MaxCardinalityRestriction mcRest = rest.asMaxCardinalityRestriction(); labelStr += "maximum cardinality "; labelStr += mcRest.getMaxCardinality(); } else if (rest.isCardinalityRestriction()) {
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); OntProperty p = m.createObjectProperty( NS + "p" ); OntProperty q = m.createObjectProperty( NS + "q" ); OntClass B = m.createClass( NS + "B" ); Restriction A = m.createAllValuesFromRestriction( NS + "A", p, B ); assertEquals( "Restriction should be on property p", p, A.getOnProperty() ); assertTrue( "Restriction should be on property p", A.onProperty( p ) ); assertTrue( "Restriction should not be on property q", !A.onProperty( q ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ON_PROPERTY() )); A.setOnProperty( q ); assertEquals( "Restriction should be on property q", q, A.getOnProperty() ); assertTrue( "Restriction should not be on property p", !A.onProperty( p ) ); assertTrue( "Restriction should not on property q", A.onProperty( q ) ); assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ON_PROPERTY() )); A.removeOnProperty( p ); assertTrue( "Should have q as on property", A.onProperty( q ) ); A.removeOnProperty( q ); assertTrue( "Should not have q as on property", !A.onProperty( q ) ); } },
OntClass rescl = (OntClass) itres.next(); if (rescl.isRestriction()) { if (rescl.asRestriction().isAllValuesFromRestriction()) { AllValuesFromRestriction avfres = rescl.asRestriction().asAllValuesFromRestriction();
@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createCardinalityRestriction( null, p, 3 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); } },
@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createMaxCardinalityRestriction( null, p, 5 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", a.isMaxCardinalityRestriction() ); } },
@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createMinCardinalityRestriction( null, p, 1 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); } },
@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createMinCardinalityRestriction( null, p, 1 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); } },
@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createCardinalityRestriction( null, p, 3 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); } },
@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); a = a.convertToMaxCardinalityRestriction( 3 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", a.isMaxCardinalityRestriction() ); } },
@Override public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); a = a.convertToMinCardinalityRestriction( 3 ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); } },