# Rules for Feature Detection
# LETRAS Project
#
# By Jonathan Clark
# Created: September 26, 2007
#
# Supported functions:
# fnode - Returns the feature node corresponding to the specified label (paren nesting important);
#		HOWEVER, as with the patterns (see below) the first element of the pattern to be
#		matched must be a role (e.g. actor/undergoer/modifier); note: this is equivalent
#		to requiring the first element of the pattern to be a labeled node. This dramatically
#		improves performance
# in-order - Returns true if the specified positions are in ascending order
# source-lex - source language lexical node/subtree associated with a f-node
# target-lex - target language lexical node/subtree associated with a f-node
#
# *-uhead - Returns the ultimate head of the specified source or target lexical node
# *-ihead - Returns the immediate head of the specified source (NOT target) lexical node
#
# NOTE: *-ihead is currently unavailable for the target lexicons since such a function
#			would have to do a lookup on a projection mapping. To get this functionality
#			we would have to integrate this program with Vamshi's projection mapping code.
#
# different - true iff there is a difference in any element of the 2 specified lexical lists
# different-suffix - true iff there are the same number of tokens in the operands and
#					there is a difference that does not include the first character of
#					any element	of the 2 specified lexical lists
# different-prefix - true iff there are the same number of tokens in the operands and
#					there is a difference that does not include the last character of
#					any element	of the 2 specified lexical lists
#
# Variables are lists of features that do not take on a value until a sentence match
#		is performed. Each variable may have a different match-time value for each sentence
#		but its value is constant within the context of that match.
# Sentences indicate a named sentence pattern that will be matched against all newly
#		elicited sentences; the given to a sentence may later be used in the IF portion
#		of the rule. A sentence is said to match the pattern if any part of the subtree
#		of the elicited sentence matches. HOWEVER, the first element of the pattern to be
#		matched must be a role (e.g. actor/undergoer/modifier); note: this is equivalent
#		to requiring the first element of the pattern to be a labeled node. This dramatically
#		improves performance. When using sentences in "if" comparisons, different variable
#		names will always refer to unique sentences; that is, a sentence will never be compared
#		with itself.

# Example illustrating "dumb heuristic" for SO order
# We assume that the actor-undergoer pattern implies active voice
# (since there is no mention of focus)
(rule	(variables	()
		(sentences	(A (actor) (undergoer))
		(if			(in-order(target-lex(fnode(A (actor)) target-lex(fnode(A (undergoer))))
		(then		(WALS "SO")))


# Example using an array of possible matches
# Example of using a variable for an array match
# X can be either the actor or undergoer
(rule	(variables	(X (actor undergoer))
		(sentences	(A (X ((np-number num-sg)))))
					(B (X ((np-number num-pl)))))
		(if			(different(target-lex(fnode(A)) target-lex(fnode(B))))
		(then		(WALS "Marks Plural")))

# This rule fires "Marks Plural Suffix" if any target language lexical items associated
# with the actor or undergoer has a different suffix
(rule	(variables	(X (actor undergoer))
		(sentences	(A ((X ((np-number num-sg)))))
					(B ((X ((np-number num-pl)))))
		(if			(different-suffix(target-lex(fnode(A (X))) target-lex(fnode(B (X)))))
		(then		(WALS "Marks Plural Suffix")))
		
# This rule fires "Marks Plural Suffix" if any target language lexical items associated
# with the actor or undergoer has a different suffix ON ITS HEAD
(rule	(variables	(X (actor undergoer))
		(sentences	(A ((X ((np-number num-sg)))))
					(B ((X ((np-number num-pl)))))
		(if			(different-suffix(target-lex-uhead(fnode(A (X))) target-lex-uhead(fnode(B (X)))))
		(then		(WALS "Marks Plural Suffix")))