# Rules for Feature Detection
# LETRAS Project
#
# By Jonathan Clark
# Created: September 26, 2007
# Version 1: October 29, 2007
# Last Modified: February 29, 2008
#
# 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
#
# Suffixes for source-lex and target-lex:
# 	   *-uhead - Returns the lexicons corresponding to the ultimate head of the
#	   	     specified f-node
# 	   *-ihead - Returns the lexicons corresponding to the immediate head of the
#	   	     specified f-node
#
# 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
#
# same
# present
# not-present
#
# In sentence vars, tree structure is exact, but in the fnode function, it just indicates subtree membership
#
# Documentation TODO: same functions (works like different)
#
# empty - see present
#
# 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.
#
# Pitfalls:
#	- Only putting one set of parentheses around f-node patterns when 2 are needed.
#	  ((actor)) will match the f-struct for a full sentence containing an actor node
#	  at the top level.
#	- Putting two sets of parentheses around f-node patterns when only 1 is needed.
#	  (actor) will match an actor f-node subtree within a f-struct, but not the whole
#	  sentence's f-struct.
#	- In general, use ((actor)) when defining sentence patterns and (A) when referencing
#	  variables. However, this is NOT correct in every situation.
#
#	- Using a sentence variable in an "if" fnode statement without any arguments following
#	  the sentence variable returns the whole sentence's f-structure NOT the node that
#	  matched the specified pattern.
#
# Recommendations:
#	- Use emacs with paren matching enabled for editing this file.

# TODO: Implement function that returns a list of additional lexicons used in a translation

# WORD ORDER
# Assume uhead of the whole sentence is the main verb
# Assume actor-undergoer pattern implies active voice (since there is no mention of focus)
(rule	(variables	())
	(sentences	(A ((actor) (undergoer)))
			(B ((actor) (undergoer))))
	(overlap	(default))
	(if		.33 (in-order
				(target-lex-uhead (fnode (A (undergoer))))
				(target-lex-uhead (fnode (A))))
		(then	(WALS "Order of Object and Verb" "OV")))
	(if		.33 (in-order
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead (fnode (A (undergoer)))))
		(then	(WALS "Order of Object and Verb" "VO")))
	(if		.33 (and
				(in-order
					(target-lex-uhead (fnode (A)))
					(target-lex-uhead (fnode (A (undergoer)))))
				(in-order
					(target-lex-uhead (fnode (B (undergoer))))
					(target-lex-uhead (fnode (B)))))
		(then	(WALS "Order of Object and Verb" "No dominant order"))))


# WORD ORDER
# Assume uhead of the whole sentence is the main verb
# Assume actor-undergoer pattern implies active voice (since there is no mention of focus)
(rule	(variables	())
	(sentences	(A ((actor) (undergoer)))
			(B ((actor) (undergoer))))
	(overlap	(all))
	(if		.33 (in-order
				(target-lex-uhead (fnode (A (actor))))
				(target-lex-uhead (fnode (A))))
		(then	(WALS "Order of Subject and Verb" "SV")))
	(if		.33 (in-order
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead(fnode (A (actor)))))
		(then	(WALS "Order of Subject and Verb" "VS")))

	(if		.33 (and
				(in-order
					(target-lex-uhead (fnode (A (actor))))
					(target-lex-uhead (fnode (A))))
				(in-order
					(target-lex-uhead (fnode (B)))
					(target-lex-uhead (fnode (B (actor))))))
		(then	(WALS "Order of Subject and Verb" "No dominant order"))))


# WORD ORDER
# Assume uhead of the whole sentence is the main verb
# Assume actor-undergoer pattern implies active voice (since there is no mention of focus)
(rule	(variables	())
	(sentences	(A ((actor) (undergoer)))
			(B ((actor) (undergoer))))
	(overlap	(all))
	(if	.5	(in-order
				(target-lex-uhead(fnode (A (actor))))
				(target-lex-uhead(fnode (A (undergoer))))
				(target-lex-uhead (fnode (A))))
		(then	(WALS "Order of Subject, Object and Verb" "SOV")))
	(if	.5	(in-order
				(target-lex-uhead(fnode (A (actor))))
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead(fnode (A (undergoer)))))
		(then	(WALS "Order of Subject, Object and Verb" "SVO")))

	(if	.5	(in-order
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead(fnode (A (actor))))
				(target-lex-uhead(fnode (A (undergoer)))))
		(then	(WALS "Order of Subject, Object and Verb" "VSO")))
	(if	.5	(in-order
				(target-lex-uhead (fnode (A)))				
				(target-lex-uhead(fnode (A (undergoer))))
				(target-lex-uhead(fnode (A (actor)))))
		(then	(WALS "Order of Subject, Object and Verb" "VOS")))

	(if	.5	(in-order
				(target-lex-uhead(fnode (A (undergoer))))
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead(fnode (A (actor)))))
		(then	(WALS "Order of Subject, Object and Verb" "OVS")))
	(if	.5	(in-order
				(target-lex-uhead(fnode (A (undergoer))))
				(target-lex-uhead(fnode (A (actor))))
				(target-lex-uhead (fnode (A))))
		(then	(WALS "Order of Subject, Object and Verb" "OSV")))
	(warning	"Does not cover case: No dominant order"))


###
###Does noun agree with verb in number?




# Nominal Categories / Articles and Pronouns
# Inclusive/Exclusive Distinction in Independent Pronouns
# Inclusive/exclusive,No inclusive/exclusive,Only inclusive,'We' the same as 'I'
#
# Who does the pronoun "we" include?
# TODO: What does "No inclusive/exclusive" mean vs "we same as i"?
# TODO: How would we detect "only inclusive"? Look for user adding extra words?
# Note: This is an example of using a variable with one value to simulate a constant
(rule	(variables	(WE ((actor ((np-person person-first)(np-number num-pl)(np-general-type pronoun-type)))))
			(I ((actor ((np-person person-first)(np-number num-sg)(np-general-type pronoun-type)))))
			(IN ((actor ((np-pronoun-exclusivity pronoun-include-second-person)))))
			(EX ((actor ((np-pronoun-exclusivity pronoun-exclude-second-person))))))
	(sentences	(A ((IN)))
			(B ((EX)))
			(C ((WE)))
			(D ((I))))
	(overlap	(default))
	(if	.1	(same
				(target-lex-uhead (fnode (C (WE))))
				(target-lex-uhead (fnode (D (I)))))
		(then	(WALS "Inclusive/Exclusive Distinction in Independent Pronouns" "'We' the same as 'I'")))
	(if	.5	(same
				(target-lex-uhead (fnode (A (IN))))
				(target-lex-uhead (fnode (B (EX)))))
		(then	(WALS "Inclusive/Exclusive Distinction in Independent Pronouns" "No inclusive/exclusive")))
	(if	.25	(different
				(target-lex-uhead (fnode (A (IN))))
				(target-lex-uhead (fnode (B (EX)))))
		(then	(WALS "Inclusive/Exclusive Distinction in Independent Pronouns" "Inclusive/exclusive")))
	(warning 	"Does not cover case: Only Inclusive"))

# Nominal Categories / Articles and Pronouns
# Inclusive/Exclusive Distinction in Verbal Inflection
# Inclusive/exclusive,No inclusive/exclusive,Only inclusive,'We' the same as 'I'
#
# Who does the pronoun "we" include?
# TODO: How would we detect "only inclusive"? Look for user adding extra words? User survey?
# Note: This is an example of using a variable with one value to simulate a constant
(rule	(variables	())
	(sentences	(S-WE-IN ((actor ((np-pronoun-exclusivity pronoun-include-second-person)
				 	 (np-general-type	 pronoun-type)
				 	 (np-person		 person-first)
					 (np-number		 num-pl)))))
			(S-WE-EX ((actor ((np-pronoun-exclusivity pronoun-exclude-second-person)
				 	 (np-general-type	 pronoun-type)
				 	 (np-person		 person-first)
					 (np-number		 num-pl)))))
			(S-I	 ((actor ((np-general-type	 pronoun-type)
				 	 (np-person		 person-first)
					 (np-number		 num-sg))))))
	(overlap	(default))
	(if	.1	(same
				(target-lex-uhead (fnode (S-WE-IN)))
				(target-lex-uhead (fnode (S-I))))
		(then	(WALS "Inclusive/Exclusive Distinction in Verbal Inflection" "'We' the same as 'I'")))
	(if	.5	(and
				(different
					(target-lex-uhead (fnode (S-WE-IN)))
					(target-lex-uhead (fnode (S-I))))
				(same
					(target-lex-uhead (fnode (S-WE-IN)))
					(target-lex-uhead (fnode (S-WE-EX)))))
		(then	(WALS "Inclusive/Exclusive Distinction in Verbal Inflection" "No inclusive/exclusive")))
	(if	.25	(and
				(different
					(target-lex-uhead (fnode (S-WE-IN)))
					(target-lex-uhead (fnode (S-I))))
				(different
					(target-lex-uhead (fnode (S-WE-IN)))
					(target-lex-uhead (fnode (S-WE-EX)))))
		(then	(WALS "Inclusive/Exclusive Distinction in Verbal Inflection" "Inclusive/exclusive")))
	(warning 	"Does not cover case: Only Inclusive"))



# Nominal Categories / Articles and Pronouns
# Politeness Distinctions in Pronouns
# Multiple politeness distinctions,Binary politeness distinction,No politeness distinction,Pronouns avoided for politeness
#
# NOTE: We require 100% overlap for this rule
(rule	(variables    	())
	(sentences	(A ((actor ((np-general-type pronoun-type)
			   	   (np-person	   person-second)))
			   (c-power-relationship power-superior)))
			(B ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-power-relationship power-inferior)))
			(C ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-power-relationship power-peer)))
			(D ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-solidarity solidarity-neutral)))
			(E ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-solidarity solidarity-positive)))
			(F ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-solidarity solidarity-negative)))
			(G ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-speaker-listener-gender s-h-male-male)))
			(H ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-speaker-listener-gender s-h-male-female)))
			(I ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-speaker-listener-gender s-h-female-male)))
			(J ((actor ((np-general-type pronoun-type)
			   	  (np-person	   person-second)))
			   (c-speaker-listener-gender s-h-female-female))))
	(overlap	(all))
	(if	.05	(= 0	(count-diff
					(target-lex-uhead (fnode (A (actor))))
					(target-lex-uhead (fnode (B (actor))))
					(target-lex-uhead (fnode (A (actor))))
					(target-lex-uhead (fnode (C (actor))))
					(target-lex-uhead (fnode (D (actor))))
					(target-lex-uhead (fnode (E (actor))))
					(target-lex-uhead (fnode (F (actor))))
					(target-lex-uhead (fnode (G (actor))))
					(target-lex-uhead (fnode (H (actor))))
					(target-lex-uhead (fnode (I (actor))))
					(target-lex-uhead (fnode (J (actor))))))
		(then	(WALS "Politeness Distinctions in Pronouns" "No politeness distinction")))
	(if	.5	(= 1	(count-diff
					(target-lex-uhead (fnode (A (actor))))
					(target-lex-uhead (fnode (B (actor))))
					(target-lex-uhead (fnode (C (actor))))
					(target-lex-uhead (fnode (D (actor))))
					(target-lex-uhead (fnode (E (actor))))
					(target-lex-uhead (fnode (F (actor))))
					(target-lex-uhead (fnode (G (actor))))
					(target-lex-uhead (fnode (H (actor))))
					(target-lex-uhead (fnode (I (actor))))
					(target-lex-uhead (fnode (J (actor))))))
		(then	(WALS "Politeness Distinctions in Pronouns" "Binary politeness distinction")))
	(if	5.0	(> 1	(count-diff
					(target-lex-uhead (fnode (A (actor))))
					(target-lex-uhead (fnode (B (actor))))
					(target-lex-uhead (fnode (C (actor))))
					(target-lex-uhead (fnode (D (actor))))
					(target-lex-uhead (fnode (E (actor))))
					(target-lex-uhead (fnode (F (actor))))
					(target-lex-uhead (fnode (G (actor))))
					(target-lex-uhead (fnode (H (actor))))
					(target-lex-uhead (fnode (I (actor))))
					(target-lex-uhead (fnode (J (actor))))))
		(then	(WALS "Politeness Distinctions in Pronouns" "Multiple politeness distinctions")))

	(warning 	"Does not cover case: Pronouns avoided for politeness"))



# Nominal Categories / Articles and Pronouns
# Gender Distinctions in Independent Personal Pronouns
#
# Note: We use a variable for number to ensure that we get the
# 	same number for both sentences that we're comparing,
#	whatever number that might be.
#
# No gender distinctions
# 1st or 2nd person but not 3rd
# 3rd person only, but also non-singular
# 3rd person singular only
# In 3rd person + 1st and/or 2nd person
# 3rd person non-singular only
(rule	(variables	(NON-SINGULAR (num-dual num-pl))
			(NON-THIRD (person-first person-second))
			(ANY-NUMBER (num-sg num-dual num-pl num-neutral)))
	(sentences	(S-MALE-12 ((actor ((np-person NON-THIRD)
				   	  (np-number ANY-NUMBER)
				       	  (np-biological-gender bio-gender-male)
				       	  (np-general-type pronoun-type)))))
			(S-MALE-12S ((actor ((np-person NON-THIRD)
				   	   (np-number num-sg)
				       	   (np-biological-gender bio-gender-male)
				       	   (np-general-type pronoun-type)))))
			(S-MALE-12P ((actor ((np-person NON-THIRD)
				   	   (np-number NON-SINGULAR)
				       	   (np-biological-gender bio-gender-male)
				       	   (np-general-type pronoun-type)))))
			(S-MALE-3 ((actor  ((np-person person-third)
				  	  (np-number ANY-NUMBER)
				       	  (np-biological-gender bio-gender-male)
				       	  (np-general-type pronoun-type)))))
			(S-MALE-3S ((actor ((np-person person-third)
				 	  (np-number num-sg)
				       	  (np-biological-gender bio-gender-male)
				       	  (np-general-type pronoun-type)))))
			(S-MALE-3P ((actor ((np-person person-third)
				 	  (np-number NON-SINGULAR)
				       	  (np-biological-gender bio-gender-male)
				       	  (np-general-type pronoun-type)))))
			(S-FEMALE-12 ((actor ((np-person NON-THIRD)
				     	    (np-number ANY-NUMBER)
				  	    (np-biological-gender bio-gender-female)
					    (np-general-type pronoun-type)))))
			(S-FEMALE-12S ((actor ((np-person NON-THIRD)
				      	     (np-number num-sg)
				  	     (np-biological-gender bio-gender-female)
					     (np-general-type pronoun-type)))))
			(S-FEMALE-12P ((actor ((np-person NON-THIRD)
				      	     (np-number NON-SINGULAR)
				  	     (np-biological-gender bio-gender-female)
					     (np-general-type pronoun-type)))))
			(S-FEMALE-3  ((actor ((np-person person-third)
				     	    (np-number ANY-NUMBER)
				  	    (np-biological-gender bio-gender-female)
					    (np-general-type pronoun-type)))))
			(S-FEMALE-3S ((actor ((np-person person-third)
				   	    (np-number num-sg)
				  	    (np-biological-gender bio-gender-female)
					    (np-general-type pronoun-type)))))
			(S-FEMALE-3P ((actor ((np-person person-third)
				   	    (np-number NON-SINGULAR)
				  	    (np-biological-gender bio-gender-female)
					    (np-general-type pronoun-type))))))
	(overlap	(default))
	(if	.05	(and
				(same
					(target-lex-uhead (fnode (S-MALE-12 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-12 (actor)))))
				(same
					(target-lex-uhead (fnode (S-MALE-3 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3 (actor))))))
		(then	(WALS "Gender Distinctions in Independent Personal Pronouns" "No gender distinctions")))
	(if	.5	(and
				(same
					(target-lex-uhead (fnode (S-MALE-12 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-12 (actor)))))
				(different
					(target-lex-uhead (fnode (S-MALE-3 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3 (actor))))))
		(then	(WALS "Gender Distinctions in Independent Personal Pronouns" "1st or 2nd person but not 3rd")))
	(if	.01	(and
				(same
					(target-lex-uhead (fnode (S-MALE-12 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-12 (actor)))))
				(different
					(target-lex-uhead (fnode (S-MALE-3S (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3S (actor)))))
				(same
					(target-lex-uhead (fnode (S-MALE-3P (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3P (actor))))))
		(then	(WALS "Gender Distinctions in Independent Personal Pronouns" "3rd person singular only")))
	(if	.01	(and
				(same
					(target-lex-uhead (fnode (S-MALE-12 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-12 (actor)))))
				(same
					(target-lex-uhead (fnode (S-MALE-3S (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3S (actor)))))
				(different
					(target-lex-uhead (fnode (S-MALE-3P (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3P (actor))))))
		(then	(WALS "Gender Distinctions in Independent Personal Pronouns" "3rd person non-singular only")))
	(if	0.9	(and
				(different
					(target-lex-uhead (fnode (S-MALE-12 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-12 (actor)))))
				(different
					(target-lex-uhead (fnode (S-MALE-3 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3 (actor))))))
		(then	(WALS "Gender Distinctions in Independent Personal Pronouns" "In 3rd person + 1st and/or 2nd person")))
	(if	0.08	(and
				(same
					(target-lex-uhead (fnode (S-MALE-12S (actor))))
					(target-lex-uhead (fnode (S-FEMALE-12S (actor)))))
				(different
					(target-lex-uhead (fnode (S-MALE-12P (actor))))
					(target-lex-uhead (fnode (S-FEMALE-12P (actor)))))
				(different
					(target-lex-uhead (fnode (S-MALE-3 (actor))))
					(target-lex-uhead (fnode (S-FEMALE-3 (actor))))))
		(then	(WALS "Gender Distinctions in Independent Personal Pronouns" "3rd person only, but also non-singular"))))




# INFLECTIONAL FUTURE TENSE
# Verbal Categories / Tense and Aspect
# The Future Tense
# Inflectional future exists,No inflectional future
(rule	(variables	(FUTURE ((c-v-absolute-tense future)))
			(PRES	((c-v-absolute-tense present))))
	(sentences	(A ((PRES)))
			(B ((FUTURE))))
	(overlap	(default))
	(if	.9	(different
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead (fnode (B))))
		(then	(WALS "The Future Tense" "Inflectional future exists")))
	(if	.1	(same
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead (fnode (B))))
		(then	(WALS "The Future Tense" "No inflectional future"))))

# Perfective/Imperfective
(rule	(variables	(PERFECTIVE	((c-v-grammatical-aspect gram-aspect-perfective)))
			(IMPERFECTIVE	((c-v-grammatical-aspect gram-aspect-habitual)
					 (c-v-grammatical-aspect gram-aspect-progressive))))
	(sentences	(A ((PERFECTIVE)(c-v-absolute-tense past)))
			(B ((IMPERFECTIVE)(c-v-absolute-tense past))))
	(overlap	(default))
	(if	.9	(different
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead (fnode (B))))
		(then	(WALS "Perfective/Imperfective Aspect" "Grammatical marking")))
	(if	.1	(same
				(target-lex-uhead (fnode (A)))
				(target-lex-uhead (fnode (B))))
		(then	(WALS "Perfective/Imperfective Aspect" "No grammatical marking"))))

# Verbal Categories / Tense and Aspect
# Position of Tense-Aspect Affixes
# Tense-aspect suffixes,Mixed type,Tense-aspect prefixes,No tense-aspect inflection,Tense-aspect tone
#
# TODO: Fix asserted functions so that order of sentence evaluation doesn't matter
# TODO: Lowercase sentences
# TODO: Implement percentages for evaluation
(rule	(variables	(TENSES-X	((c-v-absolute-tense past)
					 (c-v-absolute-tense present)
					 (c-v-absolute-tense future)
					 (c-v-absolute-tense recent-past)
					 (c-v-absolute-tense present-perfect)
					 (c-v-absolute-tense past-perfect)
					 (c-v-absolute-tense future-perfect)))
			(TENSES-Y	((c-v-absolute-tense past)
					 (c-v-absolute-tense present)
					 (c-v-absolute-tense future)
					 (c-v-absolute-tense recent-past)
					 (c-v-absolute-tense present-perfect)
					 (c-v-absolute-tense past-perfect)
					 (c-v-absolute-tense future-perfect)))
			(ASPECTS-X	((c-v-grammatical-aspect gram-aspect-perfective)
					 (c-v-grammatical-aspect gram-aspect-habitual)
					 (c-v-grammatical-aspect gram-aspect-progressive)))
			(ASPECTS-Y	((c-v-grammatical-aspect gram-aspect-perfective)
					 (c-v-grammatical-aspect gram-aspect-habitual)
					 (c-v-grammatical-aspect gram-aspect-progressive))))
	(sentences	(TENSE-A ((TENSES-X)))
			(TENSE-B ((TENSES-Y)))
			(ASPECT-A ((ASPECTS-X)))
			(ASPECT-B ((ASPECTS-Y))))
	(overlap	(default))
	(if	.5	(different-prefix
				(target-lex-uhead (fnode (TENSE-A)))
				(target-lex-uhead (fnode (TENSE-B))))
		(then	(WALS "Position of Tense-Aspect Affixes" "Tense-aspect prefixes")))
	(if	.5	(different-suffix
				(target-lex-uhead (fnode (TENSE-A)))
				(target-lex-uhead (fnode (TENSE-B))))
		(then	(WALS "Position of Tense-Aspect Affixes" "Tense-aspect suffixes")))
	(if	.01	(same
				(target-lex-uhead (fnode (TENSE-A)))
				(target-lex-uhead (fnode (TENSE-B))))
		(then	(WALS "Position of Tense-Aspect Affixes" "No tense-aspect inflection")))
	(if	.5	(different-prefix
				(target-lex-uhead (fnode (ASPECT-A)))
				(target-lex-uhead (fnode (ASPECT-B))))
		(then	(WALS "Position of Tense-Aspect Affixes" "Tense-aspect prefixes")))
	(if	.5	(different-suffix
				(target-lex-uhead (fnode (ASPECT-A)))
				(target-lex-uhead (fnode (ASPECT-B))))
		(then	(WALS "Position of Tense-Aspect Affixes" "Tense-aspect suffixes")))
	(if	.1	(same
				(target-lex-uhead (fnode (ASPECT-A)))
				(target-lex-uhead (fnode (ASPECT-B))))	
		(then	(WALS "Position of Tense-Aspect Affixes" "No tense-aspect inflection")))
	(warning	"Does not handles cases: Mixed type and Tense-aspect tone))



# Verbal Categories / Modality
# Semantic Distinctions of Evidentiality
# Indirect only,No grammatical evidentials,Direct and indirect
# 
# Note: This rule may require some disambiguation later;
# 	"No grammatical evidentials" might be a bit trigger happy
#
# We require complete lexical overlap for this rule
(rule	(variables	(X-ANY      ((c-source source-neutral)))
			(X-DIRECT   ((c-source source-visual)
				     (c-source source-auditory)
				     (c-source source-sensory-non-visual-or-auditory)))
			(X-INDIRECT ((c-source source-hearsay)
				     (c-source source-quotative)
				     (c-source source-inferred)
				     (c-source source-assumption))))
	(sentences	(S-ANY ((X-ANY)))
			(S-DIRECT ((X-DIRECT)))
			(S-INDIRECT ((X-INDIRECT))))
	(overlap	(all))
	(if	.05	(and	(same
					(target-lex (fnode (S-ANY)))
					(target-lex (fnode (S-DIRECT))))
				(same
					(target-lex (fnode (S-ANY)))
					(target-lex (fnode (S-INDIRECT)))))
		(then	(WALS "Semantic Distinctions of Evidentiality" "No grammatical evidentials")))
	(if	.5	(and  	(same
					(target-lex (fnode (S-ANY)))
					(target-lex (fnode (S-DIRECT))))
				(different
					(target-lex (fnode (S-ANY)))
					(target-lex (fnode (S-INDIRECT)))))
		(then	(WALS "Semantic Distinctions of Evidentiality" "Indirect only")))
	(if	5.0	(and  	(different
					(target-lex (fnode (S-ANY)))
					(target-lex (fnode (S-DIRECT))))
				(different
					(target-lex (fnode (S-ANY)))
					(target-lex (fnode (S-INDIRECT)))))
		(then	(WALS "Semantic Distinctions of Evidentiality" "Direct and indirect"))))

# Simple Clauses / Predication
# Zero Copula for Predicate Nominals
# Possible,Impossible
(rule	(variables	())
	(sentences	(A ((c-secondary-type secondary-copula))))
	(overlap	(all))
	(if	.1	(present	(target-lex-uhead (fnode (A))))
		(then	(WALS "Zero Copula for Predicate Nominals" "Impossible")))
	(if	.9	(not-present	(target-lex-uhead (fnode (A))))
		(then	(WALS "Zero Copula for Predicate Nominals" "Possible"))))


# Simple Clauses / Simple Clauses
# Verbal Person Marking
# Only the A argument,No person marking,Both the A and P arguments,Only the P argument,A or P argument
#
# Note: We use a variable for ANY-PERSON to hold that value constant while doing other comparisons
(rule	(variables	(ANY-PERSON (person-first person-second person-third)))
	(sentences	(A1	     ((actor ((np-person person-first))) (undergoer ((np-person ANY-PERSON)))))
			(A2	     ((actor ((np-person person-second))) (undergoer ((np-person ANY-PERSON)))))
			(A3	     ((actor ((np-person person-third))) (undergoer ((np-person ANY-PERSON)))))
			(P1 	     ((actor ((np-person ANY-PERSON))) (undergoer ((np-person person-first)))))
			(P2 	     ((actor ((np-person ANY-PERSON))) (undergoer ((np-person person-second)))))
			(P3 	     ((actor ((np-person ANY-PERSON))) (undergoer ((np-person person-third))))))
	(overlap	(default))
	(if	.05	(and	(same        (target-lex-uhead (fnode (A1)))
					     (target-lex-uhead (fnode (A2))))
				(same	     (target-lex-uhead (fnode (A2)))
					     (target-lex-uhead (fnode (A3))))
				(same        (target-lex-uhead (fnode (P1)))
				     	     (target-lex-uhead (fnode (P2))))
				(same  	     (target-lex-uhead (fnode (P2)))
				     	     (target-lex-uhead (fnode (P3)))))
		(then	(WALS "Verbal Person Marking" "No person marking")))
	(if	.5	(and	(or   (different   (target-lex-uhead (fnode (A1)))
					     	   (target-lex-uhead (fnode (A2))))
				      (different   (target-lex-uhead (fnode (A2)))
					     	   (target-lex-uhead (fnode (A3)))))
				(same  	   (target-lex-uhead (fnode (P1)))
				     	     	   (target-lex-uhead (fnode (P2))))
				(same  	   (target-lex-uhead (fnode (P2)))
				     	     	   (target-lex-uhead (fnode (P3)))))
		(then	(WALS "Verbal Person Marking" "Only the A argument")))

	(if	.5	(and	(same        (target-lex-uhead (fnode (A1)))
					     (target-lex-uhead (fnode (A2))))
				(same	     (target-lex-uhead (fnode (A2)))
					     (target-lex-uhead (fnode (A3))))
				(or	     (different   (target-lex-uhead (fnode (P1)))
				     	     		  (target-lex-uhead (fnode (P2))))
					     (different   (target-lex-uhead (fnode (P2)))
				     	     		  (target-lex-uhead (fnode (P3))))))
		(then	(WALS "Verbal Person Marking" "Only the P argument")))
	(if	5.0	(and	(different   (target-lex-uhead (fnode (A1)))
					     (target-lex-uhead (fnode (A2))))
				(different   (target-lex-uhead (fnode (A2)))
					     (target-lex-uhead (fnode (A3))))
				(different   (target-lex-uhead (fnode (P1)))
				     	     (target-lex-uhead (fnode (P2))))
				(different   (target-lex-uhead (fnode (P2)))
				     	     (target-lex-uhead (fnode (P3)))))
		(then	(WALS "Verbal Person Marking" "Both the A and P arguments")))
	(warning	"Does not handle case: A or P argument"))



# Nominal Categories / Gender and Number
# Occurrence of Nominal Plurality
#
# Only human nouns, optional (todo)
# All nouns, always optional (todo)
# Only human nouns, obligatory (done)
# All nouns, always obligatory (done)
# All nouns, optional in inanimates (todo)
# No nominal plural (done)
(rule	(variables	())
	(sentences	(HUMAN-S	((actor  ((np-number num-sg)
					       (np-animacy anim-human)))))
			(HUMAN-P	((actor  ((np-number num-pl)
					       (np-animacy anim-human)))))
			(INANIMATE-S	((actor  ((np-number num-sg)
					       (np-animacy anim-inanimate)))))
			(INANIMATE-P	((actor  ((np-number num-pl)
					       (np-animacy anim-inanimate))))))
	(overlap	(default))
	(if	5.0	(and	(different	(target-lex-uhead (fnode (HUMAN-S (actor))))
						(target-lex-uhead (fnode (HUMAN-P (actor)))))
				(different	(target-lex-uhead (fnode (INANIMATE-S (actor))))
						(target-lex-uhead (fnode (INANIMATE-P (actor))))))
		(then	(WALS "Occurrence of Nominal Plurality" "All nouns, always obligatory")))
	(if	.05	(and  	(same 		(target-lex-uhead (fnode (HUMAN-S (actor))))
						(target-lex-uhead (fnode (HUMAN-P (actor)))))
				(same		(target-lex-uhead (fnode (INANIMATE-S (actor))))
						(target-lex-uhead (fnode (INANIMATE-P (actor))))))
		(then	(WALS "Occurrence of Nominal Plurality" "No nominal plural")))
	(if	.5	(and  (different  (target-lex-uhead (fnode (HUMAN-S (actor))))
					  (target-lex-uhead (fnode (HUMAN-P (actor)))))
			      (same	  (target-lex-uhead (fnode (INANIMATE-S (actor))))
					  (target-lex-uhead (fnode (INANIMATE-P (actor))))))
		(then	(WALS "Occurrence of Nominal Plurality" "Only human nouns, obligatory")))
	(warning	"Does not handle cases that include optional"))






# Complex Sentences
# 'Want' Complement Clauses
#
# Subject is left implicit (done)
# Subject is expressed overtly (done)
# Desiderative verbal affix ? [this not mutually exclusive with subject is left implicit]
# Both construction types exist (done)
# Desiderative particle ? [this not mutually exclusive with subject is left implicit]
(rule	(variables	(NOT-WANTED (assertiveness-neutral)))
	(sentences	(WANTED	((c-assertiveness assertiveness-wanted)))
			(OTHER	((c-assertiveness NOT-WANTED))))
	(overlap	(default))
	(if	0.1	(or (not-present	(target-lex-uhead (fnode (WANTED (actor)))))
			     	(same	(target-lex-uhead (fnode (WANTED (actor))))
						(target-lex-uhead (fnode (OTHER (actor))))))
		(then	(WALS "'Want' Complement Subjects" "Subject is left implicit")))
	(if	0.1	(and (present	(target-lex-uhead (fnode (WANTED (actor)))))
			     	(different	(target-lex-uhead (fnode (WANTED (actor))))
						(target-lex-uhead (fnode (OTHER (actor))))))
		(then	(WALS "'Want' Complement Subjects" "Subject is expressed overtly")))
	(if	1.0	(and  (or  (not-present (target-lex-uhead (fnode (WANTED (actor)))))
			      	  	(same		(target-lex-uhead (fnode (WANTED (actor))))
								(target-lex-uhead (fnode (OTHER (actor))))))
			      	(and (present	(target-lex-uhead (fnode (WANTED (actor)))))
			     	        (different	(target-lex-uhead (fnode (WANTED (actor))))
					         	(target-lex-uhead (fnode (OTHER (actor)))))))
		(then	(WALS "'Want' Complement Subjects" "Both construction types exist")))

	(warning	"Does not handle case of desiderative verbal affix nor desiderative particle"))

# Nominal Syntax
# Position of Pronominal Possessive Affixes
#
# Possessive prefixes
# Possessive suffixes
# No possessive affixes
# Prefixes and suffixes
(rule	(variables	())
	(sentences	(POSSESSIVE	((actor ((possessor)))))
				(NOT-POSSESSIVE	((actor))))
	(overlap	(default))
	(if	0.5	(different-prefix (target-lex-uhead (fnode (POSSESSIVE (actor ((possessor))))))
					  	(target-lex-uhead (fnode (NOT-POSSESSIVE (actor)))))
		(then	(WALS "Position of Pronominal Possessive Affixes" "Possessive prefixes")))
	(if	0.5	(different-suffix (target-lex-uhead (fnode (POSSESSIVE (actor ((possessor))))))
					  	(target-lex-uhead (fnode (NOT-POSSESSIVE (actor)))))
		(then	(WALS "Position of Pronominal Possessive Affixes" "Possessive suffixes")))
	(if	0.005 (or (different (target-lex-uhead (fnode (POSSESSIVE (actor ((possessor))))))
					  	(target-lex-uhead (fnode (NOT-POSSESSIVE (actor)))))
				(same (target-lex-uhead (fnode (POSSESSIVE (actor ((possessor))))))
					  	(target-lex-uhead (fnode (NOT-POSSESSIVE (actor))))))
		(then	(WALS "Position of Pronominal Possessive Affixes" "No possessive affixes")))
	(if	5.0	(and (different-prefix (target-lex-uhead (fnode (POSSESSIVE (actor ((possessor))))))
					  	(target-lex-uhead (fnode (NOT-POSSESSIVE (actor)))))
				(different-suffix (target-lex-uhead (fnode (POSSESSIVE (actor ((possessor))))))
					  	(target-lex-uhead (fnode (NOT-POSSESSIVE (actor))))))
		(then	(WALS "Position of Pronominal Possessive Affixes" "Prefixes and suffixes"))))

# Simple Clauses / Predication
# Nominal and Locational Predication
#
# Different
# Identical
(rule	(variables	())
	(sentences	(NOM	((c-copula-type copula-role)))
				(LOC	((c-copula-type copula-location))))
	(overlap	(none))
	(if	1.0	(different (target-lex-uhead (fnode (NOM)))
					(target-lex-uhead (fnode (LOC))))
		(then	(WALS "Nominal and Locational Predication" "Different")))
	(if	0.25	(same 	(target-lex-uhead (fnode (NOM)))
					(target-lex-uhead (fnode (LOC))))
		(then	(WALS "Nominal and Locational Predication" "Same"))))

# Word Order
# Position of Interrogative Phrases in Content Questions
#
# Not initial interrogative phrase
# Initial interrogative phrase
# Mixed
(rule	(variables	(ROLE (actor undergoer)))
	(sentences	(QUESTION	((ROLE ((np-general-type interrogative-type))))))
	(overlap	(none))
	(if	1.0	(in-order  (target-lex-uhead (fnode (QUESTION (ROLE ((np-general-type interrogative-type))))))
				        (target-lex-uhead (fnode (QUESTION))))
		(then	(WALS "Position of Interrogative Phrases in Content Questions" "Initial interrogative phrase")))
	(if	1.0	(in-order  (target-lex-uhead (fnode (QUESTION)))
				        (target-lex-uhead (fnode (QUESTION (ROLE ((np-general-type interrogative-type)))))))
		(then	(WALS "Position of Interrogative Phrases in Content Questions" "Not initial interrogative phrase")))
	(if	5.0	(and (in-order  (target-lex-uhead (fnode (QUESTION)))
				        	  (target-lex-uhead (fnode (QUESTION (ROLE ((np-general-type interrogative-type)))))))
				(in-order  (target-lex-uhead (fnode (QUESTION (ROLE ((np-general-type interrogative-type))))))
				       	        (target-lex-uhead (fnode (QUESTION)))))
		(then	(WALS "Position of Interrogative Phrases in Content Questions" "Mixed"))))

# Word Order
# Order of Genitive and Noun
#
# Genitive-Noun
# Noun-Genitive
# No dominant order
(rule	(variables	())
	(sentences	(POSSESSIVE	((actor ((possessor))))))
	(overlap	(default))
	(if	0.5	(in-order (target-lex-uhead (fnode (POSSESSIVE (possessor))))
					  	(target-lex-uhead (fnode (POSSESSIVE (actor)))))
		(then	(WALS "Order of Genitive and Noun" "Genitive-Noun")))
	(if	0.5	(in-order (target-lex-uhead (fnode (POSSESSIVE (actor))))
				  		(target-lex-uhead (fnode (POSSESSIVE (possessor)))))
		(then	(WALS "Order of Genitive and Noun" "Noun-Genitive")))
	(if	1.0	(and (in-order (target-lex-uhead (fnode (POSSESSIVE (possessor))))
					  	(target-lex-uhead (fnode (POSSESSIVE (actor)))))
				(in-order (target-lex-uhead (fnode (POSSESSIVE (actor))))
				  		(target-lex-uhead (fnode (POSSESSIVE (possessor))))))
		(then	(WALS "Order of Genitive and Noun" "No dominant order"))))

# Word Order
# Order of Numeral and Noun
#
# Numeral-Noun
# Noun-Numeral
# No dominant order
# Numeral only modifies verb (only happens in 2 isloate languages; skip)
(rule	(variables	(ROLE (actor undergoer)))
	(sentences	(NUM	((ROLE ((modifier ((mod-role modifier-cardinal))))))))
	(overlap	(default))
	(if	0.5	(in-order (target-lex (fnode (NUM (modifier))))
					(target-lex-uhead (fnode (NUM (ROLE)))))
		(then	(WALS "Order of Numeral and Noun" "Numeral-Noun")))
	(if	0.5	(in-order (target-lex-uhead (fnode (NUM (ROLE))))
					(target-lex (fnode (NUM (modifier)))))
		(then	(WALS "Order of Numeral and Noun" "Noun-Numeral")))
	(if	1.0	(and (in-order (target-lex-uhead (fnode (NUM (ROLE))))
					(target-lex (fnode (NUM (modifier)))))
					(in-order (target-lex-uhead (fnode (NUM (ROLE))))
					(target-lex (fnode (NUM (modifier))))))
		(then	(WALS "Order of Numeral and Noun" "No dominant order")))
	(warning	"Does not handle case: Numeral only modifies verb"))

# Word Order
# Order of Adjective and Noun
#
# Adjective-Noun
# Noun-Adjective
# Only internally-headed relative clauses [we don't handle this]
# No dominant order
(rule	(variables	(ROLE (actor undergoer)))
	(sentences	(ADJ-SENT	((ROLE ((modifier ((mod-role mod-descriptor))))))))
	(overlap	(default))
	(if	1.0	(in-order (target-lex (fnode (ADJ-SENT (modifier))))
					(target-lex-uhead (fnode (ADJ-SENT (ROLE)))))
		(then	(WALS "Order of Adjective and Noun" "Adjective-Noun")))
	(if	1.0	(in-order (target-lex-uhead (fnode (ADJ-SENT (ROLE))))
					(target-lex (fnode (ADJ-SENT (modifier)))))
		(then	(WALS "Order of Adjective and Noun" "Noun-Adjective")))
	(if	1.0	(and (in-order (target-lex-uhead (fnode (ADJ-SENT (ROLE))))
					(target-lex (fnode (ADJ-SENT (modifier)))))
				(in-order (target-lex-uhead (fnode (ADJ-SENT (ROLE))))
					(target-lex (fnode (ADJ-SENT (modifier))))))
		(then	(WALS "Order of Adjective and Noun" "No dominant order")))
	(warning	"Does not handle case: Numeral only modifies verb"))






# Example using an array (variable) 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 "Test" "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 "Test" "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 "Test" "Marks Plural Suffix"))))
