From: Timea B. <tim...@gm...> - 2012-06-06 13:10:18
|
Dear XSB devel! I am working with XSB and Java through interprolog, translating an ontology into xsb syntax and performing query evaluation on it. Since the set of facts is fixed (and very big), and i want to pose different queries to it, is it possible to consult two P files, one containing the facts, the other the queries? Or somehow loading once and keeping in memory the first one, while consulting the second? Also, there might not be a fact for every concept, which means that in the query some atoms appear that do not appear in the list of asserted facts, then XSB gives me the error: "++Error[XSB/Runtime/P]: [Existence (No procedure :(usermod,/(qferry,2)) exists)] (['Forward Continuation...". How can I overcome this? Small example: :-table transport/2, city/1, coastalcity/1, train/2. coastalcity('Hastings'). city('Calais'). train('Paris','Dijon'). transport('Dover','Hastings'). country('France'). city('Dover'). exec :- q(X), writeln(X), fail. exec. q(X):- city(X). city(X):- transport(X,W),city(W). q(X):- coastalcity(X). q(X):- transport(X,_). city(X):- ferry(X,W),city(W). city(X):- train(X,W),city(W). Thanks, waiting for response. |
From: Timea B. <tim...@gm...> - 2012-06-06 13:42:01
|
I found that I can include the contents of one file into the other, so that's settled. The second question remains though, how to allow atoms on the right-hand side of a query if it never appears in the left-hand side or as a fact? Thank you. |
From: Paulo M. <pm...@di...> - 2012-06-06 13:43:58
|
On 06/06/2012, at 14:41, Timea Bagosi wrote: > I found that I can include the contents of one file into the other, so that's > settled. > The second question remains though, how to allow atoms on the right-hand side of > a query if it never appears in the left-hand side or as a fact? Either by declaring them dynamic or catching and handling the generated exception? Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275 242081 Fax: +351 275 319899 Email: <mailto:pm...@di...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- |
From: Paulo M. <pm...@di...> - 2012-06-06 15:03:53
|
Hi David, Nice to hear from you again. On 06/06/2012, at 15:01, David Warren wrote: > You can do: > > :- set_prolog_flag(unknown,fail). > > This will set a global flag that causes all unknown predicates to fail quietly. Noooooooooo! :-) I was avoided talking to Timea about that hack. And it's really an hack, not a solution. A zombie thing in the Prolog world that refuses to die :-) At least, is this flag local to a module in XSB? Or is it a global flag? > Regarding your other question, you can definitely have code (and/or data) in multiple files. I am doing something similar to you, and I always keep my data facts in .P files which I dynamically load (by calling load_dync(FileName), the "c" indicating that the facts are in "canonical form", i.e. not containing operators. This is much faster for large files than is load_dyn(FileName), which does handle all legal Prolog clauses.) And having them as dynamic code allows them to have much better indexing alternatives. Better than static code? That's interesting and I didn't expect that. > So I generally separate my "Prolog code" from my "Prolog data", compiling the code and dynamically loading the data. > > You can load (or reload) data by sending the command (e.g. load_dync(Filename)) to XSB through the interProlog interface. Of course you can also send consult(FileName) if you want to (re-)consult a file to compile and load the code. > > Be sure you are using good indexing for your large fact files. If you have issues, please ask. I'll be happy to help. As I said, I've been doing stuff similar to what you are doing for awhile and have learned a few tricks. Cheers, Paulo > -----Original Message----- > From: Paulo Moura [mailto:pm...@di...] > Sent: Wednesday, June 06, 2012 9:44 AM > To: Timea Bagosi > Cc: xsb...@li... > Subject: Re: [Xsb-development] Consult multiple P files > > > On 06/06/2012, at 14:41, Timea Bagosi wrote: > >> I found that I can include the contents of one file into the other, so >> that's settled. >> The second question remains though, how to allow atoms on the >> right-hand side of a query if it never appears in the left-hand side or as a fact? > > Either by declaring them dynamic or catching and handling the generated exception? > > Cheers, > > Paulo > > > ----------------------------------------------------------------- > Paulo Jorge Lopes de Moura, PhD > Assistant Professor > Dep. of Computer Science, University of Beira Interior > 6201-001 Covilhã, Portugal > > Office 3.18 Ext. 3276 > Phone: +351 275 242081 Fax: +351 275 319899 > Email: <mailto:pm...@di...> > > Home page: <http://www.di.ubi.pt/~pmoura> > Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> > ----------------------------------------------------------------- > > > > > > > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Xsb-development mailing list > Xsb...@li... > https://lists.sourceforge.net/lists/listinfo/xsb-development ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275 242081 Fax: +351 275 319899 Email: <mailto:pm...@di...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- |
From: Paulo M. <pm...@di...> - 2012-06-06 16:06:48
|
On 06/06/2012, at 16:48, David Warren wrote: > Regarding dynamic vs. static facts: In XSB dynamic code can be indexed in many more ways than static code. Static predicates can have only one index; it can be on any argument, and it is only on the main functor symbol of the indexed argument. Dynamic code can have multiple indexes, joint indexes (i.e. one index on multiple arguments), and the indexes can be on either the main functor symbol or the first n symbols (where n can be set globally.) Dynamic code also allows a special form for an entire predicate that we call trie-indexing. > > So for example, I can declare: > :- index(has_attr_val/3, [1+2,2+3,1]). > which says that my has_attr_val predicate (which is a set of ground facts like has_attr_val(ObjID,AttrName,AttrVal)), has 3 indexes; first if ObjId and AttrName are bound use them both to look up the AttrVals; if not, and AttrName and AttrVal are bound, then use them both to look up the ObjIDs; if not and the ObjID is bound, then use it to look up the AttrNames and AttrVals; and otherwise backtrack through the whole thing. > > And for facts, assert (and load_dyn, which does assert) generates wam-code in memory that is essentially as efficient as compiled code. And using load_dync, one can load a lot of facts in a pretty reasonable time. > > I've just added to XSB a profiling capability that allows one to find places where there is no indexing (for dynamic predicates) and I've found a few lurking inefficiencies in large, complex code, that were easy to fix by adding (or usually modifying) an index declaration... > > Anyway, if Timea (Hi!) is going to use XSB for large ontology applications, he'll need to learn about all this stuff, I'm afraid. Thanks for the informative overview on XSB indexing. I should probably be ashamed to confess that I'm not using index/2 directives in the Logtalk config file for XSB. I'm now reading more about this directive on the XSB manual and see how best I can use to speedup accessing the dynamic predicate used for caching dynamic binding predicate lookups. Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275 242081 Fax: +351 275 319899 Email: <mailto:pm...@di...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- |