Solved

Deleting anonymous variables in a Prolog list

Posted on 2007-11-17
6
390 Views
Last Modified: 2012-05-05
HI,
I have a list in Prolog containing elements and anonymous variables. I extract some elements with unification like

is_NP('NP'|Rest):-
...

the problem is that the list contains anonymous variables like _G123 which will unify with 'NP' f.e. What I want to do is to delete all the anonymous variables before I extract the needed elements. How can this be done? Normally I'd go for regex to match underscore and 'G', but SWI Prolog doesn't really support regex.

One way to do it would be to convert each element to a list itself and then proceed the list and check for the sequence underscore and 'G', but that's ugly and inefficient.
Is there a more simple way to do it?
0
Comment
Question by:Don_T
  • 3
6 Comments
 

Author Comment

by:Don_T
ID: 20311155
EDIT: I upped the points to 250
0
 
LVL 24

Expert Comment

by:fridom
ID: 20311298
I don't understand your problem. Who has put the "anonymous" variables into the list? Why were they put there? Why not simply not add them first? And how about some code which shows your problem? That one can have an idea on what'd you mean?

Regards
Friedrich
0
 

Author Comment

by:Don_T
ID: 20312015
Hi Friedrich
I'm coding a module for a bigger project and the list is generated elsewhere. It needs the anonymous variables for consistency reasons (sometimes the place held by the anonymous variables has a value). The list looks like this f.e.:

[he, PRP, He_PRP, _G229, succeed, VBN, will_MD, be_VB, succeeded_VBN, succeeded,
 by, IN, by_IN, by, ledford, NNP, Rob_NNP, Ledford_NNP, Rob Ledford, of, IN, of_
IN, of, gainesville, NNP, Gainesville_NNP, Gainesville, c, COMMA, C_COMMA, _G346
, who, WP, who_WP, _G364, be, VBN, has_VBZ, been_VBN, been, assistant, NN, an_DT
, assistant_NN, assistant, year, NNS, more_RBR, than_IN, three_CD, years_NNS, ye
ars]

What I do is extracting all NNPs, NNs, NNs, etc. for anaphora resolution. The problem is that if I pass the list to a predicate like:

is_NNP('NNP'|Rest):-
nextto(X, 'NNP', List),
...accept X as possible reference for anaphora resolution...

the anonymous variables in the list will unify with everything (because they hold no value) and deliver any results for X. So what I want is to get rid of all the anonymous variables before I look for possible referents.

0
 

Author Comment

by:Don_T
ID: 20320292
OK, I thought of a solution yesterday, I can check the list elements and see if they're atoms using atom/1 or atomic/1 and rebuild it without the anonymous variables. still not a regex to use delete/1, but works,
regards
Don
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20633885
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question