Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:48:22+00:00 2026-05-28T02:48:22+00:00

ok, so there’s basically 3 tasks this program must carry out: Parse a sentence

  • 0

ok, so there’s basically 3 tasks this program must carry out:

  1. Parse a sentence given in the form of a list, in this case (and throughout the example) the sentence will be [the,traitorous,tostig_godwinson,was,slain]. (its history, don’t ask!) so this would look like:

    sentence(noun_phrase(det(the),np2(adj(traitorous),np2(noun(tostig_godwinson)))),verb_phrase(verb(slain),np(noun(slain)))).
    
  2. use the parsed sentence to extract the subject, verb and object, and output as a list, e.g. [tostig_godwinson,was,slain] using the current example. I had this working too until I attempted number 3.

  3. use the target list and compare it against a knowledge base to basically answer the question you asked in the 1st place (see code below) so using this question and the knowledge base the program would print out ‘the_battle_of_stamford_bridge’ as this is the sentence in the knowledge base with the most matches to the list in question

so here’s where i am so far:

history('battle_of_Winwaed',[penda,       king_of_mercia,was,slain,killed,oswui,king_of_bernicians, took_place, '15_November_1655']).

history('battle_of_Stamford_Bridge',[tostig_godwinson,herald_hardrada,was,slain, took_place, '25_September_1066']).

history('battle_of_Boroughbridge',[edwardII,defeated,earl_of_lancaster,execution, took_place, '16_march_1322']).

history('battle_of_Towton',[edwardIV,defeated,henryVI,palm_Sunday]).

history('battle_of_Wakefield',[richard_of_york, took_place, 
'30_December_1490',was,slain,war_of_the_roses]).

history('battle_of_Adwalton_Moor',[earl_of_newcastle,defeats,fairfax, took_place, '30_June_1643',battle,bradford,bloody]).

history('battle_of_Marston_Moor',[prince_rupert,marquis_of_newcastle,defeats,fairfax,oliver_cromwell,ironsides, took_place, 
'2_June_1644', bloody]).

noun(penda).
noun(king_of_mercia).
noun(oswui).
noun(king_of_bernicians).
noun('15_November_1655').
noun(tostig_godwinson).
noun(herald_hardrada).
noun('25_September_1066').
noun(edwardII).
noun(earl_of_lancaster).
noun('16_march_1322').
noun(edwardIV).
noun(henryVI).
noun(palm_Sunday).
noun(richard_of_york).
noun('30_December_1490').
noun(war_of_the_roses).
noun(earl_of_newcastle).
noun(fairfax).
noun('30_June_1643').
noun(bradford).
noun(prince_rupert).
noun(marquis_of_newcastle).
noun(fairfax).
noun(oliver_cromwell).
noun('2_June_1644').
noun(battle).
noun(slain).
noun(defeated).
noun(killed).
adj(bloody).
adj(traitorous).
verb(defeats).
verb(was).
det(a).
det(the).
prep(on).

best_match(Subject,Object,Verb):-
        history(X,Y),
        member(Subject,knowledgebase),
        member(Object,knowledgebase),
        member(Verb,knowledgebase),
        write(X),nl,
        fail.
micro_watson:- write('micro_watson: Please ask me a question:'), read(X), 
sentence(X,Sentence,Subject,Object,Verb),nl,write(Subject),nl,write(Verb),nl,write(Object).

sentence(Sentence,sentence(Noun_Phrase, Verb_Phrase),Subject,Object,Verb):-
    np(Sentence,Noun_Phrase,Rem),
    vp(Rem,Verb_Phrase),
    nl, write(sentence(Noun_Phrase,Verb_Phrase)),
        noun(Subject),
    member(Subject,Sentence),
        noun(Object),
    member(Object,Rem),
    verb(Verb),
    member(Verb,Rem),
        best_match(Subject,Object,Verb).

member(X,[X|_]).
member(X,[_|Tail]):-
    member(X,Tail).
np([X|T],np(det(X),NP2),Rem):-
    det(X),
    np2(T,NP2,Rem).
np(Sentence,Parse,Rem):- np2(Sentence,Parse,Rem).
np(Sentence,np(NP,PP),Rem):-
        np(Sentence,NP,Rem1),
        pp(Rem1,PP,Rem).
np2([H|T],np2(noun(H)),T):-noun(H).
np2([H|T],np2(adj(H),Rest),Rem):- adj(H),np2(T,Rest,Rem).
pp([H|T],pp(prep(H),Parse),Rem):-
    prep(H),
    np(T,Parse,Rem).
vp([H|[]],verb(H)):-
    verb(H).
vp([H|T],vp(verb(H),Rest)):-
    verb(H),
    pp(T, Rest,_).
vp([H|T],vp(verb(H),Rest)):-
    verb(H),
    np(T, Rest,_).

As i said i had number 2 working until i tried number 3, now it just prints the parsed sentence out and then give me a ‘Error: out of local stack message’ any help is greatly appreciated! So at the top is the knowledge base with which we are comparing out list to find the best match, these are called (albeit incorrectly at this stage) by the best_match method, which executes immediately after the sentence method which parses the sentence and extract the key words. Also i apologise if the code is terribly laid out!
Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:48:22+00:00Added an answer on May 28, 2026 at 2:48 am

    I assume the person who posted this is never coming back, I wanted to remind myself some prolog, so here it is.

    There are two major issues with this code, apart from the fact that there are still some logical problems in some predicates.

    Problem 1:
    You ignored singleton warnings, and they usually are something not to be ignored. The best match predicate should look like this:

    best_match(Subject,Object,Verb):-
            history(X,Y),
            member(Subject,Y),
            member(Object,Y),
            member(Verb,Y),
            write(X),nl,
            fail.
    

    The other warning was about the Sentence variable in the sentence predicate, so it goes like this:

    sentence(X,Subject,Object,Verb),nl,write(Subject),nl,write(Verb),nl,write(Object).
    
    sentence(Sentence,Subject,Object,Verb):-
    
        np(Sentence,_,Rem),     
        vp(Rem,_),  
        nl, 
            noun(Subject),
        member(Subject,Sentence),
            noun(Object),
        member(Object,Rem),
        verb(Verb),
        member(Verb,Rem),
            best_match(Subject,Object,Verb).
    

    Problem 2:
    I assume you divided the np logic into np and np2 to avoid infinite loops, but then forgot to apply this division just where it was necessary. The longest np clause should be:

    np(Sentence,np(NP,PP),Rem):-
            np2(Sentence,NP,Rem1),
            pp(Rem1,PP,Rem).
    

    If you really wanted to allow more complicated np there, which I doubt, you can do it like this:

    np(Sentence,np(NP,PP),Rem):-
      append(List1,List2,Sentence),
      List1\=[],
      List2\=[],
      np(List1,NP,Rem1),
      append(Rem1,List2,Rem2),
      pp(Rem2,PP,Rem).
    

    This way you will not end up calling np with the same arguments over and over again, because you make sure that the sentence checked is shorter each time.

    Minor issues:
    (How the program works, after the infinite loop problem has been fixed)

    1. The last vp is repeated
    2. I am not sure about your grammar, and e.g. why "defeated" is a noun…

    Just to check that the program works I used the sentence [edwardIV,defeated,henryVI,on,palm_Sunday].

    I changed "defeated" to a verb, and also changed the last vp clause to:

    vp([H|T],vp(verb(H),Rest)):-
        verb(H),
        np(T,_,Rest1),      
        pp(Rest1, Rest,_).
    

    For the example sentence I got battle_of_Boroughbridge and battle_of_Towton as results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There must be a simple solution to this, but after 4 hours of browsing
There is previous little on the google on this subject other than people asking
There is a file as data.html. How to display the contents of this file
There's no Sort() function for IList . Can someoene help me with this? I
There are things like f.call(...) f.apply(...) But then there's this (1, alert)('Zomg what is
There are lots of posts on here about moving a folder out of one
There is a constant I'm using from the iOS SDK. I printed out the
There was some code like this: // Convenience to make things more legible in
There is about 2000 lines of this, so manually would probably take more work
There are a few ways to do this in javascript. Foremost and most readable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.