Return all restrictions in an intersection or a union in jena

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Return all restrictions in an intersection or a union in jena

Jos Lehmann-2

Hi there

 

I would like to return all restrictions in an intersection or a union*. The code below does that only for first.

The commented part of the code is an attempt at doing the same thing for rest. But that does not do the job.

Also, not knowing in advance the number of intersected classes, I guess one needs a recursive method.

Before trying to come-up with such a method I would like to know whether there already is such a method available in jena?

 

Thanks, Jos

 

* In EXAMPLE OUTPUT below I am interested in what marked as "Re-re-re-re-re-found problem" (5 x re). Beware that "problem" in trace (e.g. "Re-found problem") has no particular meaning -- it is just a message for an anonymous class.

 

 

CODE:

 

if(propertyofAnonymousClass.getPredicate().toString().contains("intersectionOf")) {

                                                                                            

                                                              ExtendedIterator anonymousClass2 = ((Resource) propertyofAnonymousClass.getSubject()).listProperties();

                                                             

                                                               while (anonymousClass2.hasNext()) {

                                                                              Statement propertyofAnonymousClass2 = (Statement) anonymousClass2.next();

                                                                              System.out.println("     Re-re-re-found problem S: " + propertyofAnonymousClass2.getSubject().toString());

                                                                              System.out.println("     Re-re-re-found problem P: " + propertyofAnonymousClass2.getPredicate().toString());

                                                                              System.out.println("     Re-re-re-found problem O: " + propertyofAnonymousClass2.getObject().toString());

                                                                              

                                                                                             ExtendedIterator anonymousClass3 = ((Resource) propertyofAnonymousClass2.getObject()).listProperties();

                                                                                            

                                                                                              while (anonymousClass3.hasNext()) {

                                                                                                              Statement propertyofAnonymousClass3 = (Statement) anonymousClass3.next();

                                                                                                              System.out.println("     Re-re-re-re-found problem S: " + propertyofAnonymousClass3.getSubject().toString());

                                                                                                              System.out.println("     Re-re-re-re-found problem P: " + propertyofAnonymousClass3.getPredicate().toString());

                                                                                                              System.out.println("     Re-re-re-re-found problem O: " + propertyofAnonymousClass3.getObject().toString());

                                                               

                                                                                                              ExtendedIterator anonymousClass4 = ((Resource) propertyofAnonymousClass3.getObject()).listProperties();

                                                                                                                            

                                                                                                              while (anonymousClass4.hasNext()) {

                                                                                                              Statement propertyofAnonymousClass4 = (Statement) anonymousClass4.next();

                                                                                                              System.out.println("     Re-re-re-re-re-found problem S: " + propertyofAnonymousClass4.getSubject().toString());

                                                                                                              System.out.println("     Re-re-re-re-re-found problem P: " + propertyofAnonymousClass4.getPredicate().toString());

                                                                                                              System.out.println("     Re-re-re-re-re-found problem O: " + propertyofAnonymousClass4.getObject().toString());                                                                                                                                         

                                                                                                              

//                                                                                                         if (propertyofAnonymousClass4.getPredicate().toString().contains("rest")) {          

//                                                                                         

//                                                                                                          ExtendedIterator anonymousClass5 = ((Resource) propertyofAnonymousClass4.getObject()).listProperties();

//                                                                                                                        

//                                                                                                          while (anonymousClass5.hasNext()) {

//                                                                                                          Statement propertyofAnonymousClass5 = (Statement) anonymousClass5.next();

//                                                                                                          System.out.println("     Re-re-re-re-re-re-found problem S: " + propertyofAnonymousClass5.getSubject().toString());

//                                                                                                          System.out.println("     Re-re-re-re-re-re-found problem P: " + propertyofAnonymousClass5.getPredicate().toString());

//                                                                                                          System.out.println("     Re-re-re-re-re-re-found problem O: " + propertyofAnonymousClass5.getObject().toString());

//                                                                                                                                                                         

//                                                                                                            }

//                                                                                          }

                                                                               }

                                                               }

                                               }

                               }

 

 

EXAMPLE OUTPUT:

 

*Found class: http://purl.oclc.org/NET/ssnx/qu/qu#Unit

Re-found problem: 1d91878f:161993faa9b:-7fae

   Re-re-found problem S: 1d91878f:161993faa9b:-7fae

   Re-re-found problem P: http://www.w3.org/2002/07/owl#intersectionOf

   Re-re-found problem O: 1d91878f:161993faa9b:-7fac

               Re-re-re-found problem S: 1d91878f:161993faa9b:-7fae

               Re-re-re-found problem P: http://www.w3.org/2002/07/owl#intersectionOf

               Re-re-re-found problem O: 1d91878f:161993faa9b:-7fac

               Re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fac

               Re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#rest

               Re-re-re-re-found problem O: 1d91878f:161993faa9b:-7faa

               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7faa

               Re-re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#rest

               Re-re-re-re-re-found problem O: 1d91878f:161993faa9b:-7fa8

               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7faa

               Re-re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#first

               Re-re-re-re-re-found problem O: 1d91878f:161993faa9b:-7fab

               Re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fac

               Re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#first

               Re-re-re-re-found problem O: 1d91878f:161993faa9b:-7fad

               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad

               Re-re-re-re-re-found problem P: http://www.w3.org/2002/07/owl#onClass

               Re-re-re-re-re-found problem O: http://purl.oclc.org/NET/ssnx/qu/qu#QuantityKind

               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad

               Re-re-re-re-re-found problem P: http://www.w3.org/2002/07/owl#maxQualifiedCardinality

               Re-re-re-re-re-found problem O: 1^^http://www.w3.org/2001/XMLSchema#nonNegativeInteger

               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad

               Re-re-re-re-re-found problem P: http://www.w3.org/2002/07/owl#onProperty

               Re-re-re-re-re-found problem O: http://purl.oclc.org/NET/ssnx/qu/qu#quantityKind

               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad

               Re-re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type

               Re-re-re-re-re-found problem O: http://www.w3.org/2002/07/owl#Restriction

               Re-re-re-found problem S: 1d91878f:161993faa9b:-7fae

               Re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type

               Re-re-re-found problem O: http://www.w3.org/2002/07/owl#Class

   Re-re-found problem S: 1d91878f:161993faa9b:-7fae

   Re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type

   Re-re-found problem O: http://www.w3.org/2002/07/owl#Class

   

 

 


_______________________________________________
protege-dev mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-dev
Reply | Threaded
Open this post in threaded view
|

Re: Return all restrictions in an intersection or a union in jena

Matthew Horridge-2
Administrator
Hi Jos,

Working at the triple-level for this sort of thing isn’t easy.  Protege uses the OWLAPI, which has a higher-level representation of axioms and their components at the level of OWL.  I recommend that you use this instead instead of viewing things at a raw triple level.  If you need to use Jena, for whatever reason, then you should get support for this question on the Jena support forum or list as we don’t support it here.

Cheers,

Matthew



On 15 Feb 2018, at 03:56, Jos Lehmann <[hidden email]> wrote:

Hi there 
 
I would like to return all restrictions in an intersection or a union*. The code below does that only for first.
The commented part of the code is an attempt at doing the same thing for rest. But that does not do the job.
Also, not knowing in advance the number of intersected classes, I guess one needs a recursive method.
Before trying to come-up with such a method I would like to know whether there already is such a method available in jena?
 
Thanks, Jos
 
* In EXAMPLE OUTPUT below I am interested in what marked as "Re-re-re-re-re-found problem" (5 x re). Beware that "problem" in trace (e.g. "Re-found problem") has no particular meaning -- it is just a message for an anonymous class.
 
 
CODE: 
 
if(propertyofAnonymousClass.getPredicate().toString().contains("intersectionOf")) {
                                                                                            
                                                              ExtendedIterator anonymousClass2 = ((Resource) propertyofAnonymousClass.getSubject()).listProperties();
                                                             
                                                               while (anonymousClass2.hasNext()) {
                                                                              Statement propertyofAnonymousClass2 = (Statement) anonymousClass2.next();
                                                                              System.out.println("     Re-re-re-found problem S: " + propertyofAnonymousClass2.getSubject().toString());
                                                                              System.out.println("     Re-re-re-found problem P: " + propertyofAnonymousClass2.getPredicate().toString());
                                                                              System.out.println("     Re-re-re-found problem O: " + propertyofAnonymousClass2.getObject().toString());
                                                                              
                                                                                             ExtendedIterator anonymousClass3 = ((Resource) propertyofAnonymousClass2.getObject()).listProperties();
                                                                                            
                                                                                              while (anonymousClass3.hasNext()) {
                                                                                                              Statement propertyofAnonymousClass3 = (Statement) anonymousClass3.next();
                                                                                                              System.out.println("     Re-re-re-re-found problem S: " + propertyofAnonymousClass3.getSubject().toString());
                                                                                                              System.out.println("     Re-re-re-re-found problem P: " + propertyofAnonymousClass3.getPredicate().toString());
                                                                                                              System.out.println("     Re-re-re-re-found problem O: " + propertyofAnonymousClass3.getObject().toString());
                                                               
                                                                                                              ExtendedIterator anonymousClass4 = ((Resource) propertyofAnonymousClass3.getObject()).listProperties();
                                                                                                                            
                                                                                                              while (anonymousClass4.hasNext()) {
                                                                                                              Statement propertyofAnonymousClass4 = (Statement) anonymousClass4.next();
                                                                                                              System.out.println("     Re-re-re-re-re-found problem S: " + propertyofAnonymousClass4.getSubject().toString());
                                                                                                              System.out.println("     Re-re-re-re-re-found problem P: " + propertyofAnonymousClass4.getPredicate().toString());
                                                                                                              System.out.println("     Re-re-re-re-re-found problem O: " + propertyofAnonymousClass4.getObject().toString());                                                                                                                                          
                                                                                                              
//                                                                                                         if (propertyofAnonymousClass4.getPredicate().toString().contains("rest")) {          
//                                                                                         
//                                                                                                          ExtendedIterator anonymousClass5 = ((Resource) propertyofAnonymousClass4.getObject()).listProperties();
//                                                                                                                        
//                                                                                                          while (anonymousClass5.hasNext()) {
//                                                                                                          Statement propertyofAnonymousClass5 = (Statement) anonymousClass5.next();
//                                                                                                          System.out.println("     Re-re-re-re-re-re-found problem S: " + propertyofAnonymousClass5.getSubject().toString());
//                                                                                                          System.out.println("     Re-re-re-re-re-re-found problem P: " + propertyofAnonymousClass5.getPredicate().toString());
//                                                                                                          System.out.println("     Re-re-re-re-re-re-found problem O: " + propertyofAnonymousClass5.getObject().toString());
//                                                                                                                                                                         
//                                                                                                            }
//                                                                                          }
                                                                               }
                                                               }
                                               }
                               }
 
 
EXAMPLE OUTPUT:
 
Re-found problem: 1d91878f:161993faa9b:-7fae
   Re-re-found problem S: 1d91878f:161993faa9b:-7fae
   Re-re-found problem P: http://www.w3.org/2002/07/owl#intersectionOf
   Re-re-found problem O: 1d91878f:161993faa9b:-7fac
               Re-re-re-found problem S: 1d91878f:161993faa9b:-7fae
               Re-re-re-found problem P: http://www.w3.org/2002/07/owl#intersectionOf
               Re-re-re-found problem O: 1d91878f:161993faa9b:-7fac
               Re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fac
               Re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#rest
               Re-re-re-re-found problem O: 1d91878f:161993faa9b:-7faa
               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7faa
               Re-re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#rest
               Re-re-re-re-re-found problem O: 1d91878f:161993faa9b:-7fa8
               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7faa
               Re-re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#first
               Re-re-re-re-re-found problem O: 1d91878f:161993faa9b:-7fab
               Re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fac
               Re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#first
               Re-re-re-re-found problem O: 1d91878f:161993faa9b:-7fad
               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad
               Re-re-re-re-re-found problem P: http://www.w3.org/2002/07/owl#onClass
               Re-re-re-re-re-found problem O: http://purl.oclc.org/NET/ssnx/qu/qu#QuantityKind
               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad
               Re-re-re-re-re-found problem P: http://www.w3.org/2002/07/owl#maxQualifiedCardinality
               Re-re-re-re-re-found problem O: 1^^http://www.w3.org/2001/XMLSchema#nonNegativeInteger
               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad
               Re-re-re-re-re-found problem P: http://www.w3.org/2002/07/owl#onProperty
               Re-re-re-re-re-found problem O: http://purl.oclc.org/NET/ssnx/qu/qu#quantityKind
               Re-re-re-re-re-found problem S: 1d91878f:161993faa9b:-7fad
               Re-re-re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type
               Re-re-re-re-re-found problem O: http://www.w3.org/2002/07/owl#Restriction
               Re-re-re-found problem S: 1d91878f:161993faa9b:-7fae
               Re-re-re-found problem P: http://www.w3.org/1999/02/22-rdf-syntax-ns#type
               Re-re-re-found problem O: http://www.w3.org/2002/07/owl#Class
   Re-re-found problem S: 1d91878f:161993faa9b:-7fae
   Re-re-found problem O: http://www.w3.org/2002/07/owl#Class
    
 

 

_______________________________________________
protege-dev mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-dev


_______________________________________________
protege-dev mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-dev