protegeproject / protege

Protege Desktop
http://protege.stanford.edu
Other
971 stars 229 forks source link

SPARQL Tab Comes up Empty in 5.6 if You Have Ontology Open #1110

Open mdebellis opened 1 year ago

mdebellis commented 1 year ago

This is a low priority IMO because I almost never use the SPARQL Tab anyway, perhaps it should just be removed. But there was something I wanted to do that Snap SPARQL didn't support (coercing strings to decimals using: "xsd:decimal(?numstr)" ) that I wanted to try to see if the SPARQLTab might support. If you just open Protégé and do Windows>Tab>SPARQL Query you get the normal SPARQL query. But if you first open an ontology and then do Windows>Tab>SPARQL Query the SPARQL Tab is empty and you can't enter a query and there is a bug in the log:

Sparql Tab in 5-6

Beginning of bug trace from log: 
 INFO  10:17:25  Disposed of 'DL Query' tab
   INFO  10:17:25  Disposed of workspace
   INFO  10:17:25  
   INFO  10:17:26  [IdRanges] Updating entity creation preferences
  ERROR  10:17:44  Uncaught Exception in thread 'AWT-EventQueue-0'
java.lang.NoSuchMethodError: 'void org.semanticweb.owlapi.rdf.model.AbstractTranslator.<init>(org.semanticweb.owlapi.model.OWLOntologyManager, org.semanticweb.owlapi.model.OWLOntology, boolean, org.semanticweb.owlapi.util.IndividualAppearance, org.semanticweb.owlapi.util.AxiomAppearance, java.util.concurrent.atomic.AtomicInteger, java.util.Map)'
    at org.protege.owl.rdf.impl.RDFTranslator.<init>(RDFTranslator.java:107) ~[na:na]
    at org.protege.owl.rdf.impl.RDFTranslator.translate(RDFTranslator.java:55) ~[na:na]
    at org.protege.owl.rdf.impl.OwlTripleStoreImpl.addAxiom(OwlTripleStoreImpl.java:99) ~[na:na]
    at org.protege.owl.rdf.Utilities.loadOwlTripleStore(Utilities.java:48) ~[na:na]
    at org.protege.owl.rdf.Utilities.getOwlTripleStore(Utilities.java:32) ~[na:na]
    at org.protege.editor.owl.rdf.repository.Basic
SparqlReasoner.precalculate(BasicSparqlReasoner.java:54) ~[na:na]
    at org.protege.editor.owl.rdf.SparqlQueryView.initializeReasoner(SparqlQueryView.java:34) ~[na:na]
    at org.protege.editor.owl.rdf.SparqlQueryView.initialiseOWLView(SparqlQueryView.java:24) ~[na:na]
LorenzBuehmann commented 1 year ago

Happens because of OWL API version conflict, specific issue opened here: https://github.com/protegeproject/rdf-library/issues/12

LeleDallas commented 1 year ago

Same issue on mac m1

santos-sicilia commented 11 months ago

Hi, I am suffering the same problem. What is the solution? I have reached a repository with AbstractTranslator.java file but I unknow how to fix the problem.

Best Regards, Leo

mdebellis commented 11 months ago

Unfortunately, to the best of my knowledge the only "fix" is to use something else. It's a known bug that has been documented on the Protege github site. In any case, IMO the Snap SPARQL Plugin is better than the default SPARQL tab anyway. You have to load Snap SPARQL from the plugin menu. Once you do that and restart Protege go to Window>Views>Query Views>Snap SPARQL Query

You will then be prompted to add the Snap SPARQL view to some tab. Best to navigate to that tab ahead of time (or create a new tab). I usually put Snap SPARQL on to the DL Query tab because I often go back and forth between the two. I think Snap SPARQL is better (besides the fact that it actually works when you have an ontology open) for several reasons:

1) It can see inferences by the reasoner

2) You can use it to add info to the ontology. I don't think you can do that with the default SPARQL tab. Neither of them support INSERT or DELETE which is the standard way to use SPARQL to add info but if you do CONSTRUCT {...} then Snap SPARQL will match anything in the ",,," and the WHERE clause and give you a list of triples. It will then ask you if you want to add those triples to your ontology. I often use that for basic things like adding labels to entities that I created with user defined names: https://www.michaeldebellis.com/post/refactoring-names-w-sparql

3) Snap SPARQL provides you with prompts as you write your query so you can see if something won't parse and if so where the problem probably is.

Snap SPARQL has some limitations though. One of them is I don't think it support a wild card in the predicate position. E.g., if you want to see all the properties that link the individuals :Foo and :Bar you should be able to do:

SELECT * WHERE {:Foo ?fbpred :Bar}

You should be able to do that but it won't work in Snap SPARQL.

Michael

On Wed, Aug 2, 2023 at 10:15 AM santos-sicilia @.***> wrote:

Hi, I am suffering the same problem. What is the solution? I have reached a repository with AbstractTranslator.java file but I unknow how to fix the problem.

Best Regards, Leo

— Reply to this email directly, view it on GitHub https://github.com/protegeproject/protege/issues/1110#issuecomment-1662634310, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7TPBBLV7UQM2AV76QOMBTXTKDLPANCNFSM6AAAAAAVRPHIDA . You are receiving this because you authored the thread.Message ID: @.***>

santos-sicilia commented 11 months ago

Thanks Michael,

But I have tried a simple query with Snap SPARQL and I cannot understand why it does not work. The query is:

PREFIX owl: http://www.w3.org/2002/07/owl# PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema# PREFIX bfiao: http://www.semanticweb.org/leopo/ontologies/2021/0/BFiaO_v1.24#

SELECT ?subclass where { ?subclass rdfs:subClassOf bfiao:node }

Instead of listing all the subclasses of node, I get a syntax error in SPARQL query: "Encountered bfiao:node at line 7 column 30. Expected one of: Variable Class name (prefix name)"

Do you have any idea of this syntax error? (thanks in advance) Leo

mdebellis commented 11 months ago

It sounds like bfiao:node is not a class. Although I also wonder if bfiao:node is an instance or any entity in the ontology because I think if it was then you wouldn't get a syntax error. You wouldn't get any results but I don't think it would be a syntax error. BTW, if you want to see all the subclasses in your ontology you can just do:

SELECT * WHERE {?subclass rdfs:subClassOf ?superclass}

You could also do:

SELECT * WHERE {?subclass rdfs:subClassOf owl:Thing}

Make sure you run the reasoner first.

Michael

On Wed, Aug 2, 2023 at 11:22 AM santos-sicilia @.***> wrote:

Thanks Michael,

But I have tried a simple query with Snap SPARQL and I cannot understand why it does not work. The query is:

PREFIX owl: http://www.w3.org/2002/07/owl# PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema# PREFIX bfiao: http://www.semanticweb.org/leopo/ontologies/2021/0/BFiaO_v1.24#

SELECT ?subclass where { ?subclass rdfs:subClassOf bfiao:node }

Instead of listing all the subclasses of node, I get a syntax error in SPARQL query: "Encountered bfiao:node at line 7 column 30. Expected one of: Variable Class name (prefix name)"

Do you have any idea of this syntax error? (thanks in advance) Leo

— Reply to this email directly, view it on GitHub https://github.com/protegeproject/protege/issues/1110#issuecomment-1662730165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7TPBC3BWTUJWVIXEPVL3DXTKLFXANCNFSM6AAAAAAVRPHIDA . You are receiving this because you authored the thread.Message ID: @.***>

santos-sicilia commented 11 months ago

Thanks again Michael,

Your sentences work perfectly but I would like to be more restrictive and just obtain the subclasses of an specific class. It is quite curious that with a specific class of the ontology it does not work. It is a pity that I cannot load an image to show you a part of the ontology with node as a class.

In any case, thanks for your time !! Leo

mdebellis commented 11 months ago

Leo, I'm replying here because I didn't want to take up the bandwidth of the whole list for this. First, have you done my revised Pizza tutorial? If you haven't I think it would be worthwhile although you might want to skip the parts on SWRL and SHACL but I have a section on SPARQL that is a good overview: https://www.michaeldebellis.com/post/new-protege-pizza-tutorial

Second, you can use the same pattern as I used to get the subclasses of owl:Thing to get the subclasses of any class. Just replace owl:Thing with dmn:MyClass where dmn is a correctly prefixed namespace for your ontology. Make sure you run the reasoner first and that should work in Snap SPARQL.

Third, you can take screenshots of your ontology and send them to me directly: mdebellissf@gmail.com I use Snipping Tool on Windows and whatever OS you are on there must be something similar. It depends how much time I have but I often spend an hour or so a day helping random new users with basic OWL questions. You can also just send your ontology to me as long as it isn't too large. In the future when you submit things to the Protégé list it is best to include screen snapshots and the ontology as well (as long as the ontology is fairly small). That makes it much easier for me and others to debug things. It depends who has time, often no one has the time to debug ontologies but sometimes people like me and others can just take a quick look and spot basic issues very quickly so if the ontology is small (which is usually the case for new users) it is best to attach it when you submit a message to the list. Good luck, feel free to let me know if you need more help.

santos-sicilia commented 11 months ago

Thank you very much Michael,

I have followed your tutorial, and everything worked with the previous Protégé version. But I will follow your advise and try it again just to see if I have done some mistake with the PREFIX and the ontology.

I will send you some screenshots of the ontology to your email. I am sure that there is something simple behind but I cannot see it yet. I promise no to abuse your time, and of course I really appreciate it.

yasenstar commented 10 months ago

Thanks for the information and workaround.

The Issue is still there in Protege 5.6.2, hope it can be fixed soon in future version.

During learning Michael's tutorial, I've made one specific video on this issue through certain testing, for your reference: https://youtu.be/oz1JaawLmJQ

trapperkeeper commented 5 months ago

I just wanted to add a bit of information to this issue. Some have suggested using the Snap SPARQL plugin as an alternative. It is worth mentioning that the Snap SPARQL plugin does not support property path expressions (e.g does not support all of SPARQL 1.1).

LorenzBuehmann commented 5 months ago

As I mentioned in my first comment, this is an easy to fix issue, the Github issue is also there: https://github.com/protegeproject/rdf-library/issues/12 But it looks like not being that important or nobody had time to invest.

As a workaround, I uploaded a fixed rdf-library JAR file at my fork: https://github.com/LorenzBuehmann/rdf-library/

Maybe @mdebellis can give it a try.

gouttegd commented 5 months ago

this is an easy to fix issue

Maybe not, unfortunately – even if rdf-library is updated to use the same version of the OWL API as Protégé itself, it still causes Protégé to hang when attempting to use the SPARQL Query tab.

LorenzBuehmann commented 5 months ago

Can't reproduce this with Protege 5.6.3 and the rdf-library file I uploaded here

image

Did you replace the existing rdf-library.jar file? What does the log say when it hangs? Is there still the exception?

java.lang.NoSuchMethodError: 'void org.semanticweb.owlapi.rdf.model.AbstractTranslator.<init>(org.semanticweb.owlapi.model.OWLOntologyManager, org.semanticweb.owlapi.model.OWLOntology, boolean, org.semanticweb.owlapi.util.IndividualAppearance, org.semanticweb.owlapi.util.AxiomAppearance, java.util.concurrent.atomic.AtomicInteger, java.util.Map)'
gouttegd commented 5 months ago

Yes, I replaced the existing rdf-library.jar file. I tried both with your build and my own build from the tip of RDF-Library’s master branch, both on macOS and GNU/Linux (Protégé 5.6.3 in both cases). Same result.

The library and the SPARQL plugins are loaded fine without errors, but Protégé hangs as soon as I try to get to the SPARQL Query tab. No exceptions, nothing at all in the log.

vjborges commented 3 months ago

Can't reproduce this with Protege 5.6.3 and the rdf-library file I uploaded here

image

Did you replace the existing rdf-library.jar file? What does the log say when it hangs? Is there still the exception?

java.lang.NoSuchMethodError: 'void org.semanticweb.owlapi.rdf.model.AbstractTranslator.<init>(org.semanticweb.owlapi.model.OWLOntologyManager, org.semanticweb.owlapi.model.OWLOntology, boolean, org.semanticweb.owlapi.util.IndividualAppearance, org.semanticweb.owlapi.util.AxiomAppearance, java.util.concurrent.atomic.AtomicInteger, java.util.Map)'

Thanks very much. It works for me.

mdebellis commented 3 months ago

Just tried it and still get the same error. I didn't try loading any jar files or anything so perhaps that's the problem, I notice it seems to be calling an undefined method in rdf.model. I had an ontology open and when I tried to open the SPARQL tab I get the following error. Note: the error may have to do with the GUI because when I do Window>Tabs>SPARQL Query I don't see any error messages but then when I click on the new SPARQL tab, I see the error below and I can't enter anything into the SPARQL tab, it doesn't respond. I'm running on Windows 11 Pro.

ERROR 17:25:26 Uncaught Exception in thread 'AWT-EventQueue-0' java.lang.NoSuchMethodError: 'void org.semanticweb.owlapi.rdf.model.AbstractTranslator.(org.semanticweb.owlapi.model.OWLOntologyManager, org.semanticweb.owlapi.model.OWLOntology, boolean, org.semanticweb.owlapi.util.IndividualAppearance, org.semanticweb.owlapi.util.AxiomAppearance, java.util.concurrent.atomic.AtomicInteger, java.util.Map)' at org.protege.owl.rdf.impl.RDFTranslator.(RDFTranslator.java:107) ~[na:na] at org.protege.owl.rdf.impl.RDFTranslator.translate(RDFTranslator.java:55) ~[na:na] at org.protege.owl.rdf.impl.OwlTripleStoreImpl.addAxiom(OwlTripleStoreImpl.java:99) ~[na:na] at org.protege.owl.rdf.Utilities.loadOwlTripleStore(Utilities.java:48) ~[na:na] at org.protege.owl.rdf.Utilities.getOwlTripleStore(Utilities.java:32) ~[na:na] at org.protege.editor.owl.rdf.repository.BasicSparqlReasoner.precalculate(BasicSparqlReasoner.java:54) ~[na:na] at org.protege.editor.owl.rdf.SparqlQueryView.initializeReasoner(SparqlQueryView.java:34) ~[na:na] at org.protege.editor.owl.rdf.SparqlQueryView.initialiseOWLView(SparqlQueryView.java:24) ~[na:na] at org.protege.editor.owl.ui.view.AbstractOWLViewComponent.initialise(AbstractOWLViewComponent.java:43) ~[na:na] at org.protege.editor.core.ui.view.View.createContent(View.java:413) ~[na:na] at org.protege.editor.core.ui.view.View.createUI(View.java:220) ~[na:na] at org.protege.editor.core.ui.view.View$1.hierarchyChanged(View.java:124) ~[na:na] at java.desktop/java.awt.Component.processHierarchyEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.processEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.processEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.dispatchEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.createHierarchyEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.createHierarchyEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.createHierarchyEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.createHierarchyEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.createHierarchyEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.createHierarchyEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.show(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.show(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.setVisible(Unknown Source) ~[na:na] at java.desktop/javax.swing.JComponent.setVisible(Unknown Source) ~[na:na] at java.desktop/javax.swing.JTabbedPane.fireStateChanged(Unknown Source) ~[na:na] at java.desktop/javax.swing.JTabbedPane$ModelListener.stateChanged(Unknown Source) ~[na:na] at java.desktop/javax.swing.DefaultSingleSelectionModel.fireStateChanged(Unknown Source) ~[na:na] at java.desktop/javax.swing.DefaultSingleSelectionModel.setSelectedIndex(Unknown Source) ~[na:na] at java.desktop/javax.swing.JTabbedPane.setSelectedIndexImpl(Unknown Source) ~[na:na] at java.desktop/javax.swing.JTabbedPane.setSelectedIndex(Unknown Source) ~[na:na] at java.desktop/javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(Unknown Source) ~[na:na] at java.desktop/java.awt.AWTEventMulticaster.mousePressed(Unknown Source) ~[na:na] at java.desktop/java.awt.AWTEventMulticaster.mousePressed(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.processMouseEvent(Unknown Source) ~[na:na] at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.processEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.processEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.dispatchEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source) ~[na:na] at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source) ~[na:na] at java.desktop/java.awt.Component.dispatchEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source) ~[na:na] at java.desktop/java.awt.EventQueue$4.run(Unknown Source) ~[na:na] at java.desktop/java.awt.EventQueue$4.run(Unknown Source) ~[na:na] at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na] at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) ~[na:na] at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) ~[na:na] at java.desktop/java.awt.EventQueue$5.run(Unknown Source) ~[na:na] at java.desktop/java.awt.EventQueue$5.run(Unknown Source) ~[na:na] at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na] at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) ~[na:na] at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source) ~[na:na] at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) ~[na:na] at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) ~[na:na] at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) ~[na:na] at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source) ~[na:na] at java.desktop/java.awt.EventDispatchThread.run(Unknown Source) ~[na:na]

vjborges commented 3 months ago

I used the jar available here - https://github.com/LorenzBuehmann/rdf-library/releases/tag/rdf-library-3.0.0

yasenstar commented 3 months ago

Using the jar file mentioned by @vjborges, which I just place it in my Protege 5.6.3's plugins folder, leave the old rdf-library-3.0.0.jar still there, and the SPARQL query tab is now working fine. Thanks @vjborges

LorenzBuehmann commented 3 months ago

That won't work keeping the old JAR still in use.

According to the README,

remove rdf-library-3.0.0.jar from $PROTEGE_HOME/plugins

knbknb commented 2 months ago

@gouttegd After replacing the Protege-5.6.2/plugins/rdf-library-3.0.0.jar file with Lorenz' patched version, and after placing the SPARQL query view on the SPARQL query tab, I saw a "ghost frame" (a transparent rectangle with grey border) where the view was about to be placed, and the Protege app was in a nonresponsive state for a while.

However I had to wait 3 minutes for the blank rectangle to disappear. Finally the SPARQL query tab showed up and was usable again even when an ontology was loaded. I have tried only 1 simple SPARQL queries though.

So I had to wait really long time, no idea what protege was doing.

LorenzBuehmann commented 2 months ago

Protege works with OWL API as Java library to load and process OWL ontologies. SPARQL on the other hand is based on RDF, and as Java library rdf4j or better said its predecessor Sesame is being used. So Protege has to convert from OWL API to Sesame API - this happens once you open the SPARQL query tab or to be more precise its wrapped SPARQL query view.

Each OWL axiom a is converted to a set of RDF triples T_a, then those triples are added to an in-memory triple store. To keep track of the correspondence between axiom and triples, i.e. as a kind of provenance, ''T_a'' is loaded into a separate named graph g_a.

Depending on the size of the data it may take some time, but I can't judge if a 3 minute waiting time is realistic.
What is the size of your ontology?

knbknb commented 2 months ago

I've used the relatively big, recent DBPedia Ontology - After the initial import , reopening Protege with that big ontology works much faster, almost instantly. The point is, The nonresponsive "hanging state" happened only once.

In any event, thanks for your great patched jar file. Respect! It really blows my my how you have figured that out. It requires so much background knowledge.