Is there any straight-forward way in OWLAPI to find all IRIs used in an ontology which have not been identified as Entities i.e. have not been declared and are not used in a context which would allowed them to be identified as a specific entity type? Hoping for something analogous to OWLOntology.signature(), didn't see anything.
An example of that situation appears in BFO 2.0 (http://purl.obolibrary.org/obo/bfo.owl) :
<rdf:Description rdf:about="http://example.com/bfo-spec-label">
<obo:IAO_0000119>Person:Alan Ruttenberg</obo:IAO_0000119>
</rdf:Description>
Here http://example.com/bfo-spec-label is just a "bare" IRI of unknown entity type and thus does not appear in the ontology signature.
Couldn't find any elegant way to find all of these bare IRI's but these can be found by looking in all places they could possibly occur. A simple method would look like:
private List findBareIRIs(OWLOntology onto) {
List bares = new ArrayList();
// bare IRIs can occur as AnnotationSubjects, AnnotationObjects or the domain/range of AnnotationProperties
List<OWLAnnotationAssertionAxiom> asserts = OWLAPIStreamUtils.asList(onto.axioms(AxiomType.ANNOTATION_ASSERTION));
List<OWLAnnotationPropertyDomainAxiom> domains = OWLAPIStreamUtils.asList(onto.axioms(AxiomType.ANNOTATION_PROPERTY_DOMAIN));
List<OWLAnnotationPropertyRangeAxiom> ranges = OWLAPIStreamUtils.asList(onto.axioms(AxiomType.ANNOTATION_PROPERTY_RANGE));
//check the subject and values of each AnnotationAsertion
for (OWLAnnotationAssertionAxiom ax : asserts) {
OWLAnnotationSubject subj = ax.getSubject();
OWLAnnotationValue value = ax.getValue();
if (subj.isIRI()) {
bares.add((IRI) subj);
}
if (value.isIRI()) {
bares.add((IRI) value);
}
}
// check the domain and ranges of each AnnotationProperty
for (OWLAnnotationPropertyDomainAxiom ax : domains) {
bares.add(ax.getDomain());
}
for (OWLAnnotationPropertyRangeAxiom ax : ranges) {
bares.add(ax.getRange());
}
return bares;
}
Related
I'm working on a plain java command line software which performs a recursive LDAP search with Spring LDAP, starting from a specified group and searching all the users from the specified groups and subgroups.
The search fails to find anything if the group distinguished name contains organisational units (=ou), but works in other cases.
Here is the short version of implementation, recursion omitted:
private void searchLdapGroup(List<UserDTO> users, LdapTemplate ldapTemplate, String groupName) {
// recursion guard omitted
String base = groupName.substring(groupName.indexOf(',') + 1);
AndFilter filter = new AndFilter().and(new EqualsFilter("objectclass", "group")).and(new EqualsFilter("memberof", groupName));
List<String> subgroups = ldapTemplate.search(base, filter.encode(), new GroupNameMapper());
// recursive calls for subgroups omitted
getAllUsers(users, ldapTemplate, groupName, base);
}
private void getAllUsers(List<UserDTO> users, LdapTemplate ldapTemplate, String groupName, String base) {
AndFilter filter = new AndFilter().and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("memberof", groupName));
// Paged search omitted.
List<UserDTO> result = ldapTemplate.search(base,filter.encode(),new UserAttributesMapper());
users.addAll(result);
}
The GroupNameMapper returns distinguishedName as Strings and UserAttributesMapper returns user objects from different attributes such as sAMAccountName and givenName.
The code (with recursion) finds all the 36 users in the first test group, where the specified group is like:
CN=import_users,CN=Users,DC=example,DC=test,DC=org
in the same exact test environment it returns zero persons and subgroups when the group distinguished name contains one or more organisational units, such as
CN=import_users,OU=testou,DC=example,DC=test,DC=org
This can't be due to wrong group distinguished name, "memberof" not working or group containing no users, since i tested lookup:
String[] test = (String[])ldapTemplate.lookup("CN=import_users,OU=testou,DC=example,DC=test,DC=org", new ContextMapper() {
public Object mapFromContext(Object ctx) {
DirContextAdapter adapter = (DirContextAdapter) ctx;
return adapter.getStringAttributes("Member");
}
});
which finds
CN=John Doe,CN=Users,DC=example,DC=test,DC=org
and lookup for the user John Doe
String[] test = (String[])ldapTemplate.lookup("CN=John Doe,CN=Users,DC=example,DC=test,DC=org", new ContextMapper() {
public Object mapFromContext(Object ctx) {
DirContextAdapter adapter = (DirContextAdapter) ctx;
return adapter.getStringAttributes("memberof");
}
});
gives results:
CN=import_users,OU=testou,DC=example,DC=test,DC=org
CN=import_users,CN=Users,DC=example,DC=test,DC=org
How come the search does not find anything when organisational units are involved?
Library user:
spring-ldap-core - 2.0.4.RELEASE
The devil is in the details:
The member of the group CN=import_users,OU=testou,DC=example,DC=test,DC=org is
CN=John Doe,CN=Users,DC=example,DC=test,DC=org
But you appear to be searching for users under
OU=testou,DC=example,DC=test,DC=org
That is, it appears all users are under CN=Users,DC=example,DC=test,DC=org, but when you are actually searching for users you assume they are placed relative to the group.
In the OWL API, I am unable to find a way to retrieve the equivalent class for a datatype that defines an enumeration of valid values. When I have an OWLDatatype in hand, how do I get a set of allowed values?
[I tried pasting RDF/XML as a code block here, but it doesn't work. I even looked at the markdown help. Please tell me how to do that.]
The ontology is using the following construct:
rdfs:Datatype
owl:equivalentClass
rdfs:Datatype
owl:oneOf
rdf:Description
rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
If understand correctly, you have a specific class "c" that has been defined as equivalent to oneOf many individuals, then I think this is one way to get those "allowed values":
Set<OWLClassAxiom> allAx=localOntology.getAxioms(c);
for(OWLClassAxiom ax: allAx){
if(ax.getAxiomType()==AxiomType.EQUIVALENT_CLASSES)
for(OWLClassExpression nce :ax.getNestedClassExpressions())
if(nce.getClassExpressionType()==ClassExpressionType.OBJECT_ONE_OF)
for(OWLNamedIndividual temp: nce.getIndividualsInSignature())
System.out.println(temp);
}
Here's what I came up with:
for (OWLDatatype dt : o.getDatatypesInSignature(Imports.INCLUDED)) {
logger.info("found datatype {} labeled '{}'", dt, getOWLEntityLabel(dt));
Set<OWLDatatypeDefinitionAxiom> datatypeDefinitions = o.getDatatypeDefinitions(dt);
for (OWLDatatypeDefinitionAxiom definitionAxiom : datatypeDefinitions) {
logger.info("found datatype definition '{}'", definitionAxiom);
OWLDataRange dataRange = definitionAxiom.getDataRange();
if ( ! dataRange.isDatatype()) {
logger.info("looks like an enumeration");
OWLDataOneOf owlDataOneOf = (OWLDataOneOf) dataRange;
Set<OWLLiteral> values = owlDataOneOf.getValues();
for (OWLLiteral value : values) {
logger.info("Found literal value '{}'", value.getLiteral());
}
}
}
}
I really don't like the cast to OWLDataOneOf. There must be a better way.
Can someone tell me what "PathSegment model = info.getPathSegments().get(1);" do, specifically, what does he getPathSegments().get(1) mean? Please provide a sample URL for demonstration. The book didn't give an example URL for this one.
Also, is there such a thing as get(0); ?
#Path("/cars/{make}")
public class CarResource
{
#GET
#Path("/{model}/{year}")
#Produces("image/jpeg")
public Jpeg getPicture(#Context UriInfo info)
{
String make = info.getPathParameters().getFirst("make");
PathSegment model = info.getPathSegments().get(1);
String color = model.getMatrixParameters().getFirst("color");
...
}
}
Thanks again,
If you split the path of a URL by a '/' you'll get a list of path-segments. So e.g. the path /cars/ford/mustang/1976 contains the four segments [cars, ford, mustang, 1976]. info.getPathSegments().get(1) should return the segment ford.
The PathSegment holds also the associated MatrixParameters of the current segment. MatrixParameters can be used if you want to filter the resources with a parameter that affects only one segment like here:
/cars/ford/mustang;generation=two/1976
I have this many to many association between KundeInfo and HovedKategori, which I have mapped in my MS SQL database like this:
I have implemented the methods KundeInfo.HovedKategoris:
public IEnumerable<KundeInfo> KundeInfos
{
get
{
using (var dc = new DataClassesBSMAKSDataContext())
{
dc.DeferredLoadingEnabled = false;
var kundeInfoHovedKategoris = dc.KundeInfoHovedKategoris.Where(x => x.HovedKategori_Id == Id);
var kundeInfos = dc.KundeInfos.Where(x => kundeInfoHovedKategoris.Any(y => y.KundeInfo_Id == x.Id));
return kundeInfos.ToList();
}
}
}
... and HovedKategori.KundeInfos:
public IEnumerable<HovedKategori> HovedKategoris
{
get
{
using (var dc = new DataClassesBSMAKSDataContext())
{
var kundeInfoHovedKategoris = dc.KundeInfoHovedKategoris.Where(x => x.KundeInfo_Id == Id);
var hovedKategoris = dc.HovedKategoris.Where(x => kundeInfoHovedKategoris.Any(y => y.HovedKategori_Id == x.Id));
return hovedKategoris.ToList();
}
}
}
This retrieves the associated KundeInfos from a specific HovedKategori and opposite. The problemhowever lies in the serialization. When I call ToList(), or serialize these objects to JSON, linq will try to first follow all references returned by HovedKategori.KundeInfos, if it were that method I were to call first, and then it would for each returned object, try to follow all references returned by KundeInfo.HovedKategoris and so on, until it would cast a stack overflow exception.
If I could somehow prevent linq from following certain properties with an [Ignore] attribute or something, it would work, but I haven't been able to find anything like that.
What can I do in this situation?
This is in part a design issue. What you should really ask yourself is if you need navigation properties in every possible direction. For example if you just add a Kategori ID instead of a navigation property you could still query your context (by using the ID) but do you really need to always get all the Kategori's with all underlying data?
also if you make your properties virtual you have lazy loading and will only get the information if you .Include it or explicitly reference it.
Ok - So I solved this problem by just making it into methods on the respective classes, which it should be in the first place, since it retrieved these entities from the database. So yes, partially design issue.
Virtual did not work, I considered using projection and an abstract class, but it would be such a haystack of inheritance, and class casts, that it would not even be worth considering.
public IEnumerable<KundeInfo> KundeInfos()
{
using (var dc = new DataClassesBSMAKSDataContext())
{
var kundeInfoHovedKategoris = dc.KundeInfoHovedKategoris.Where(x => x.HovedKategori_Id == Id);
var kundeInfos = dc.KundeInfos.Where(x => kundeInfoHovedKategoris.Any(y => y.KundeInfo_Id == x.Id));
return kundeInfos.ToList();
}
}
I know there are more elaborate ways to achieve this in Java, but Groovy should have a concise way to do the same as per http://groovy.codehaus.org/Looping
Class Currency.groovy
class Currency {
String name
double rate
}
CurrencyController
def select(){
List<Currency> selectedCurrencies = Currency.getAll(params.currencies)
selectedCurrencies.eachWithIndex { obj, i -> obj.rate = update(obj.name)};
[selectedCurrencies:selectedCurrencies]
}
def update(String sym){
return sym
}
The above code throws:
No signature of method: currencychecker.CurrencyController$_$tt__select_closure12.doCall() is applicable for argument types: (currencychecker.Currency)
Thanks to #dmahapatro, the issue was that I was using an iterator variable obj[i], even though obj itself is the iterated object. The rest is correct!
I experimented with selectCurrencies.each as well instead of selectCurrencies.eachWithIndex however the right one in this case is eachWithIndex