User Tools

Site Tools


public:t-malv-15-3:8

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
public:t-malv-15-3:8 [2015/10/06 13:00] orvarkpublic:t-malv-15-3:8 [2024/04/29 13:33] (current) – external edit 127.0.0.1
Line 10: Line 10:
  
 The exercise can be divided into two distinct parts: The exercise can be divided into two distinct parts:
-  - 1. Semantic analysis of the natural language input using a parser and a grammar with semantic attachments, resulting in a FOL representation of the input. +  - Semantic analysis of the natural language input using a parser and a grammar with semantic attachments, resulting in a FOL representation of the input. 
-  - 2. EvaluatingtheFOLrepresentationoftheinputagainstamodelcreated to represent a particular state of a􏰚airs in the world.+  - Evaluating the FOL representation of the input against a model created to represent a particular state of affairs in the world.
  
 ===== 1. Parsing using "feature-based CFG" with semantic attachments ===== ===== 1. Parsing using "feature-based CFG" with semantic attachments =====
  
-**Semantic analysis of the natural language input using a parser and a grammar with semantic attachments, resulting in a FOL representation of the input.**+**Semantic analysis of the natural language input using a parser and a grammar with semantic attachments, resulting in a [[https://en.wikipedia.org/wiki/First-order_logic|First-Order Logic]] (FOLrepresentation of the input.**
  
 You can perform syntax-driven semantic analysis of the natural language input sentence (as seen in chapters 18.1 and 18.2 in the text book) by building a NLTK parser from a "feature-based context free grammar" (fcfg) that contains semantic attachments as features. [[http://www.nltk.org/book/ch09.html|Feature-based parsing is covered in chapter 9 in the NLTK book]]. You can perform syntax-driven semantic analysis of the natural language input sentence (as seen in chapters 18.1 and 18.2 in the text book) by building a NLTK parser from a "feature-based context free grammar" (fcfg) that contains semantic attachments as features. [[http://www.nltk.org/book/ch09.html|Feature-based parsing is covered in chapter 9 in the NLTK book]].
Line 27: Line 27:
 >>> tokens = sentence.split() >>> tokens = sentence.split()
 >>> for tree in parser.parse(tokens): >>> for tree in parser.parse(tokens):
-...     print(tree.label()['SEM'])+...     print(tree.label()['SEM'])     ## print the resulting semantic representation
 all z2.(dog(z2) -> exists z1.(bone(z1) & give(angus,z1,z2))) all z2.(dog(z2) -> exists z1.(bone(z1) & give(angus,z1,z2)))
 </code> </code>
Line 71: Line 71:
 m = nltk.Model(val.domain, val) m = nltk.Model(val.domain, val)
  
-m.evaluate("...", var_assignments)+m.evaluate("...", var_assignments) ## evaluate a semantic representation given the world model
 </code> </code>
  
Line 78: Line 78:
 ===== 3. Interactive python script ===== ===== 3. Interactive python script =====
  
-Once you have the two parts working you glue them together in a python script. You should allow users to type in sentences and see their truth value printed until they 􏰛finally type "quit". When the program starts, you should print out some useful information, for instance, provide samples of sentences that would produce results.+Once you have the two parts working you glue them together in a python script. You should allow users to type in sentences and see their truth value printed until they finally type "quit". When the program starts, you should print out some useful information, for instance, provide samples of sentences that would produce results.
  
 <code> <code>
Line 90: Line 90:
 </code> </code>
  
 +**Note** that ''tree.label()['SEM']'' returns an object of type ''nltk.sem.logic.ApplicationExpression'' (as can be seen by checking its type with ''type()'') and not a string even though you can print it out. To use it in ''evaluate()'' it has to be turned into a string. The simplest way to do that is to use ''str(semantic_expression)'' or the format operator ''"%s" % semantic_representation'' which return a string.
/var/www/cadia.ru.is/wiki/data/attic/public/t-malv-15-3/8.1444136449.txt.gz · Last modified: 2024/04/29 13:32 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki