How to use pointers in VP.

Discussions related to Visual Prolog
ahmednadi
VIP Member
Posts: 84
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 4 May 2012 20:34

Hi Sir;

Pointer as in my view in this problem is used to calling a certain case from the 90 cases perdicate.

Thank you in advance for your cooperation.

Cheers

AHMED NADY.

User avatar
Thomas Linder Puls
VIP Member
Posts: 1621
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 6 May 2012 22:51

Parsing is a complex matter.

When parsing it is very important to avoid searching forward to see if "xxx" appears "soon". Because such searching will absolutely certainly result in very inefficient parsing.

It looks like you want to deal with natural language (or close to natural language).

For programming computers we invent artificial languages (like Visual Prolog). Such languages have many goals, but very important is that they can be parsed efficiently.

Natural language is quite different: not nearly as rigid, often not as concise, etc.

From an efficiency point of view the important thing is that you don't scan back and forth over the text in order to figure out what it means. Understanding must take place when advancing from the start to the end.

There are many techniques available for dealing with languages defined in terms of BNF grammars or the like. There is a parser generator among the examples in the Commercial Edition. It can create a recursive decent parser from an BNF like specification (quite like what is known from Definite Caluse Grammars).

In my opinion this is however a dead end for dealing with natural language, because the language never turns out to be near natural. You end with a programming language, and becaus it looks like natural language you think you know it; but you don't. And, unlike a human, the computer will simply not understand anything unless you follow the grammar rules 100%.

I believe the most successful approaches to natural language are based on statistical analysis of huge (really huge) amounts of real world language. But this is completely outside the "small project" context.

So unfortunately I don't really have a suggestion.

There is no silver bullit (and it is certainly not named "pointer").
Regards Thomas Linder Puls
PDC

dominique f pannier
VIP Member
Posts: 98
Joined: 23 Sep 2002 23:01

Unread post by dominique f pannier » 7 May 2012 15:20

As I understand your parser :

1. I cannot find any interest to the concept of pointer : it is mainly done to jump at a location in the memory, and to deal with arrays. And you work at a very higher level : on sentences, and part of sentences. Prolog allows you to build an easier understandable program.

2. You get at each case a repetitive handling :
- isMember
- tryGetIndex
- split_delimiter
- ...
You could study another way :
split your texte in sequences (between two commas, for example), and for each sequence store token and the rest of the sequence in an internal database : you'll win speed by avoiding repetitive handles on long strings.

3. Like Thomas suggested, you should also build a tree of cases : looking for "as if " and "although" could be eliminated if you first look does not find the 'a' character.

To summerize, you have to find an elegant and heuristic method of parsing adjusted to your goal. I think like Thomas, of course, that it's better if it is not the whole natural languaqe... :wink:
Regards
Dominique Pannier

ahmednadi
VIP Member
Posts: 84
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 11 Jul 2012 21:48

Hi Sir;
By "pointer" I mean a number that refers to a location of a data structure in memory"
Thank you
AHMED

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 12 Jul 2012 12:01

I think you need to step back from "implementation" and think more abstractly about what it is you are trying to do.

If you are trying to parse a user entered natural lanquage statement or question, Thomas's earlier post is spot on about BNFs and DCGs.

You stated you need to point to 90 clauses. Have you defined a limited language set and the rules for word use (subject-verb order, query structure, etc) - (which puts us back to BNFs, DCGs and your own programming language discussions)?

From what has been posted so far, it is hard to tell the scope of your effort.

The parser example in the commercial edition if a good basic level example. there was also an example in the earlier VIP versions going all the way back to the Turbo Prolog days.

Again, because from the limited context explained here in the forum, we don't know what you have done so far, but my recommendation is to step back, then on "paper' and with no regard for the software implenetation language, map out how you wish the system to understand the entries. How do you want the system to breakdown the entered query. What are the rules the system must follow. In the process you will effectively build an BNF/DCG roadmap. Once you have that, then approach the software implementation. And in this case, VIP is a good tool to do exactly that. With a clear set of rules and a defined structure, using a very limited langauge vocabulary/dictionary , building this will be clearer and possbily easier.


good Luck,
P.
AI Rules!
P.

User avatar
George
VIP Member
Posts: 313
Joined: 19 Sep 2011 8:54

Unread post by George » 12 Jul 2012 12:03

I have a very long predicate consists of 90 cases and each time the whole cases in the predicate should be tested sequentially to reached the right case which match the conditions and then the required processing done.

A lot of time consumption and many threads are done

May be you can re-arranging the cut(!) and bring the POSList validation at the top will give you less time consumption..

try the following code that i modified..

Code: Select all

clauses         parser(Sentence,WLst,POSList):-             list::isMember ("as",WLst),             list::isMember ("if",WLst),             not(list::isMember("0",POSList)), %do a not equality check for POSList at this place and put a cut immediately             !,  %put a cut here to avoid backtracking if it met the above condition             Index1 = list::tryGetIndex("as",WLst),             Index2 = list::tryGetIndex("if",WLst),             if Index1 <> 0 then                     SectionsLst=string::split_delimiter(Sentence,"as if"),                     my_main::sentTrim(SectionsLst,SecLst),                     stdio::writef("SecLst: %",SecLst), stdio::nl,                     pparse(SecLst,POSLst1),                     POSLst2=list::appendList(POSLst1),                     insertItem(POSLst2,Index1,"conj",POSLst3),                     insertItem(POSLst3,Index2,"conj",POSList)             else                     SignPosition = search(Sentence, ","),                     string::front(Sentence, SignPosition, Begin, End),                     string::hasPrefix(Begin, "as if", Rest),                     SectionsLst=[Rest, End],                     stdio::writef("SectionsLst: %",SectionsLst), stdio::nl,                     pparse(SectionsLst,POSLst1),                     POSLst2=list::appendList(POSLst1),                     insertItem(POSLst2,Index1,"conj",POSLst3),                     insertItem(POSLst3,Index2,"conj",POSList)             end if,             stdIO::nl.                     parser(Sentence,WLst,POSList):-             list::isMember ("although",WLst),                 not(list::isMember("0",POSList)), %do a not equality check for POSList at this place and put a cut immediately             !,  %put a cut here to avoid backtracking if it met the above condition             Index = list::tryGetIndex("although",WLst),             stdio::writef("Index: %", Index),stdio::nl,             if Index <> 0 then                     SectionsLst=string::split_delimiter(Sentence,"although"),                     my_main::sentTrim(SectionsLst,SecLst),                     stdio::writef("SecLst: %",SecLst), stdio::nl,                     pparse(SecLst,POSLst1),                     POSLst2=list::appendList(POSLst1),                     insertItem(POSLst2,Index,"conj",POSList)             else                     SignPosition = search(Sentence, ","),                     string::front(Sentence, SignPosition, Begin, End),                     string::hasPrefix(Begin, "although", Rest),                     SectionsLst=[Rest, End],                     stdio::writef("SectionsLst: %",SectionsLst), stdio::nl,                     pparse(SectionsLst,POSLst1),                     POSLst2=list::appendList(POSLst1),                     insertItem(POSLst2,Index,"conj",POSList)             end if,             stdIO::nl.                     parser(Sentence,WLst,POSList):-             list::isMember ("though",WLst),             not(list::isMember("0",POSList)), %do a not equality check for POSList at this place and put a cut immediately             !,  %put a cut here to avoid backtracking if it met the above condition             Index = list::tryGetIndex("though",WLst),             stdio::writef("Index: %", Index),stdio::nl,             if Index <> 0 then                     SectionsLst=string::split_delimiter(Sentence,"though"),                     my_main::sentTrim(SectionsLst,SecLst),                     stdio::writef("SecLst: %",SecLst), stdio::nl,                     pparse(SecLst,POSLst1),                     POSLst2=list::appendList(POSLst1),                     insertItem(POSLst2,Index,"conj",POSList)             else                     SignPosition = search(Sentence, ","),                     string::front(Sentence, SignPosition, Begin, End),                     string::hasPrefix(Begin, "though", Rest),                     SectionsLst=[Rest, End],                     stdio::writef("SectionsLst: %",SectionsLst), stdio::nl,                     pparse(SectionsLst,POSLst1),                     POSLst2=list::appendList(POSLst1),                     insertItem(POSLst2,Index,"conj",POSList)             end if,                 stdIO::nl.
:idea:
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282

User avatar
George
VIP Member
Posts: 313
Joined: 19 Sep 2011 8:54

Unread post by George » 12 Jul 2012 13:24

Additionally,

Since the following logic is same to every predicate, you can modify the calling place like follows,

Code: Select all

goParaser(Sentence,WLst,POSList):- %write a new predicate         if not(list::isMember("0",POSList)) then                 parser(Sentence,WLst,POSList)         end if,         !. goParaser(_Sentence,_WLst,_POSList).
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282

Post Reply