Erinevus lehekülje "Ask a query about Obama" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
 
(ei näidata sama kasutaja üht vahepealset redaktsiooni)
1. rida: 1. rida:
  
This example is a small modification of the obama1.txt problem, with an actual question added and a bit less output.
+
== Initial setting ==
 +
 
 +
We repeat the obama1.txt scenario in this section.
  
 
Suppose we have a triplet
 
Suppose we have a triplet
37. rida: 39. rida:
 
</pre>
 
</pre>
  
= Yes/No question =
+
= Asking a Yes/No question =
  
 
Now we add the <b>question</b>: is Obama mortal? We add the question in a negated form, like this:
 
Now we add the <b>question</b>: is Obama mortal? We add the question in a negated form, like this:
98. rida: 100. rida:
 
     "id:type",
 
     "id:type",
 
     "mortal").  
 
     "mortal").  
 
end_of_list.
 
</pre>
 
 
Just send it to otter via standard inpt:
 
<pre>
 
otter < obama2.txt
 
</pre>
 
 
and look at the --- PROOF --- in output.
 
 
It is a good idea to send the output to a file and then process it later, like this:
 
 
<pre>
 
otter < obama2.txt > obama2.out
 
</pre>
 
 
 
= A task: question with a factual output =
 
 
Now we add the <b>task</b>: find something mortal. We add the question in a negated form with a special <b>$ans</b> predicate added to capture a value, like this:
 
 
<pre>
 
-rdf(X,
 
    "id:type",
 
    "mortal") |
 
$ans(X).
 
</pre>
 
 
The whole problem obama3.txt with the strategy selection and everything, ready to run:
 
 
<pre>
 
% clear automatic strategy selection
 
clear(auto).
 
 
% use capital letters (A,X,T,...) as vars
 
set(prolog_style_variables).
 
 
% select the search strategy
 
set(hyper_res). % an alternative is to use set(binary_res).
 
set(factor).
 
 
% select sensible amount of output
 
clear(print_given). % remove to see search process milestones
 
clear(print_kept).  % do not print out generated and kept clauses.
 
assign(stats_level, 0).
 
 
% just make it stop after N secs
 
assign(max_seconds, 10).
 
 
list(sos).
 
 
% example data
 
 
rdf("http://en.wikipedia.org/wiki/Barack_Obama",
 
      "id:type",
 
      "http://conceptnet5.media.mit.edu/web/c/en/person").
 
     
 
% some simple taxonomy rules of the form A->B i.e. -A | B in clause form.
 
 
-rdf(X,"id:type",
 
    "http://conceptnet5.media.mit.edu/web/c/en/person") |
 
rdf(X,"id:type",
 
    "http://conceptnet5.media.mit.edu/web/c/en/animal").
 
 
 
-rdf(X,"id:type",
 
    "http://conceptnet5.media.mit.edu/web/c/en/animal") |
 
rdf(X,"id:type",
 
    "mortal").  
 
   
 
-rdf(X,"id:type",
 
    "http://conceptnet5.media.mit.edu/web/c/en/person") |
 
  rdf(X,"id:CapableOf",
 
    "id:eat").
 
 
% our question (negated)
 
 
-rdf(X,
 
    "id:type",
 
    "mortal") |
 
$ans(X).
 
  
 
end_of_list.
 
end_of_list.

Viimane redaktsioon: 3. november 2017, kell 09:49

Initial setting

We repeat the obama1.txt scenario in this section.

Suppose we have a triplet

http://en.wikipedia.org/wiki/Barack_Obama,
id:type,
http://conceptnet5.media.mit.edu/web/c/en/person

then we encode it in the otter format like this:

  
  rdf("http://en.wikipedia.org/wiki/Barack_Obama",
      "id:type",
      "http://conceptnet5.media.mit.edu/web/c/en/person").

and then we add three handmade common-sense taxonomy rules (observe that A->B is equivalent to -A | B)

	  
  -rdf(X,"id:type",
      "http://conceptnet5.media.mit.edu/web/c/en/person") |
   rdf(X,"id:type",
      "http://conceptnet5.media.mit.edu/web/c/en/animal").
	  
   -rdf(X,"id:type",
      "http://conceptnet5.media.mit.edu/web/c/en/animal") |
   rdf(X,"id:type",
      "mortal").	  
  	  
   -rdf(X,"id:type",
      "http://conceptnet5.media.mit.edu/web/c/en/person") |
    rdf(X,"id:CapableOf",
      "id:eat").	  

Asking a Yes/No question

Now we add the question: is Obama mortal? We add the question in a negated form, like this:

-rdf("http://en.wikipedia.org/wiki/Barack_Obama",
     "id:type",
     "mortal"). 

The whole problem obama2.txt with the strategy selection and everything, ready to run:

% clear automatic strategy selection
clear(auto).

% use capital letters (A,X,T,...) as vars
set(prolog_style_variables).

% select the search strategy
set(hyper_res). % an alternative is to use set(binary_res).
set(factor).

% select sensible amount of output
clear(print_given). % remove to see search process milestones
clear(print_kept).  % do not print out generated and kept clauses.
assign(stats_level, 0).

% just make it stop after N secs
assign(max_seconds, 10).

list(sos).

% example data

 rdf("http://en.wikipedia.org/wiki/Barack_Obama",
      "id:type",
      "http://conceptnet5.media.mit.edu/web/c/en/person").
      
% some simple taxonomy rules of the form A->B i.e. -A | B in clause form.

-rdf(X,"id:type",
    "http://conceptnet5.media.mit.edu/web/c/en/person") |
 rdf(X,"id:type",
    "http://conceptnet5.media.mit.edu/web/c/en/animal").
  
 -rdf(X,"id:type",
    "http://conceptnet5.media.mit.edu/web/c/en/animal") |
 rdf(X,"id:type",
    "mortal").	  
    
 -rdf(X,"id:type",
    "http://conceptnet5.media.mit.edu/web/c/en/person") |
  rdf(X,"id:CapableOf",
    "id:eat").

% our question (negated)

-rdf("http://en.wikipedia.org/wiki/Barack_Obama",
     "id:type",
     "mortal"). 

end_of_list.

Just send it to otter via standard inpt:

otter < obama2.txt

and look at the --- PROOF --- in output.

It is a good idea to send the output to a file and then process it later, like this:

otter < obama2.txt > obama2.out