[Question]
  [
# Task
Your task is to write a function or a program in a language of your choice that analyzes a couple of statements and determines whether it can be concluded from those statements that pigs are able to fly.
# Input
The input is a String that can be read from STDIN, taken as a function argument or even be stored in a file. The input can be described using the following EBNF:
```
input = statement , {statement};
statement = (("Pigs are ", attribute) | ("Everything that is ", attribute, "is also ", attribute)), ". ";
attribute = [not], ("able to fly" | singleAttribute);
singleAttribute = letter, {letter};
letter = "a" | "b" | "c" | "d" | "e" | "f" | "g"
       | "h" | "i" | "j" | "k" | "l" | "m" | "n"
       | "o" | "p" | "q" | "r" | "s" | "t" | "u"
       | "v" | "w" | "x" | "y" | "z" ;
```
**Example input (see more examples below):**
```
Pigs are green. Everything that is green is also intelligent. Everything that is able to fly is also not intelligent. Pigs are sweet. 
```
# Output
The output can be returned by your function, be written to a file or print to STDOUT. There are 5 different cases to be handled:
1. The given statements are valid, consistent and have as a logical consequence that pigs can fly. In that case, you must output `Yes`.
2. The given statements are valid, consistent and have as a logical consequence that pigs can not fly. In that case, you must output `No`.
3. It can not be concluded from the given, valid and consistent statements whether pigs can fly or not. In that case, you must output `Maybe`.
4. The given statements are valid, but not consistent (i.e. there's a contradiction in the given statements). Since *ex falso quodlibet*, we decide to output `Yes` in that case.
5. The given statements are not valid, i.e. they are not formatted according to the given EBNF. In that case, you may do whatever you want.
# Details
* You may assume that the given attributes are independent from each other. So, for example, a pig may be young and old, green, red and blue at the same time without causing any inconsistency. However, a pig may not be 'green' and 'not green' at the same time, that's a contradiction and should be handled as described in (4).
* For every attribute, assume that there is at least one object (not necessarily a pig) in the universe that has the given attribute, and one object that doesn't have it.
# Example Inputs & Outputs
**Input:**
```
Pigs are green. Everything that is green is also intelligent. Everything that is able to fly is also not intelligent. 
```
**Output:** Since Pigs are green and therefore intelligent, and everything that is able to fly is not intelligent, pigs cannot fly. Output is `No`.
**Input:**
```
Pigs are old. Everything that is not able to fly is also not old. 
```
**Output:** If pigs were not able to fly, they were also not old. But as they are old, you must output `Yes`.
**Input:**
```
Everything that is sweet is also not old. Everything that is intelligent is also blue. 
```
**Output:** `Maybe`.
**Input:**
```
Pigs are not able to fly. Everything that is red is also sweet. Everything that is sweet is also not red. 
```
**Output:** Although the first statement implies that pigs can not fly, the following statements contradict each other and therefore the output must be `Yes`.
**Input:**
```
Pigs are very smart. Pigs are able to fly. 
```
**Output:** Whatever you want, as the String doesn't match the criteria mentioned above.
# Winner
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest correct answer (in bytes) wins. The winner will be chosen one week after the first correct answer is posted.
![A flying Pig](https://i.stack.imgur.com/qV1jO.jpg)
  
[Answer]
# Perl, 363 353 350 347 343 297 266 264
```
$_=<>;s/able to fly/X/g;$m=' ?(not )?\b(P|\w+)';$h{$1?N.$2:$2}{$3?N.$4:$4}=$h{$3?$4:N.$4}{$1?$2:N.$2}=1while s/$m.{8}$m\.//;map{%x=0,r($_,$_)}%h;sub r{($a,$b)=@_;$e+=$h{$a}{N.$b};$x{$b}++or$h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}}print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe
```
Ungolfed/Explanation:
```
# Read one line from STDIN
$_=<>;
# Replaces special attribute with X
s/able to fly/X/g;
# Prepare attribute match
$m=' ?(not )?\b(P|\w+)';
# Match "Everything that is A is also B. "
#                        "\bA........ \bB\."
# Match "Pigs are B. "
#     "\bP........\bB\."
while(s/$m.{8}$m\.//)
{
  # Add facts for A => B and !B => !A, where A may equal "P" for "Pigs are"
  # Facts are stored as a hash of hashes %h; keys%h are the source attributes;
  # keys%{$h{$a}} are the attributes that follow from attribute $a
  # A "not attribute" is stored as "Nattribute", while a "attribute" is just stored as "attribute"
  $h{$1?N.$2:$2}{$3?N.$4:$4}=$h{$3?$4:N.$4}{$1?$2:N.$2}=1
}
# For all known source attributes ... (this should really be keys%h but we dont mind the extra hashrefs)
map{%x=0,r($_,$_)}%h;
sub r
{
  ($a,$b)=@_;
  # ... remember that we hit a negation and therefor an inconsistency ...
  # If we check/add $b and find an existing "N$b" that means that attribute $b is supposed to be true and not true at the same time
  # It is cheaper bytewise to just add up all consistency errors (remember each fact has a hard value of 1) than to exit right here
  $e+=$h{$a}{N.$b};
  # ... remember that we processed this attribute for the current source attribute so we prevent loops ...
  $x{$b}++or
  # ... add a new fact and then follow the chains (again omitting keys).
  $h{$a}{$b}=1,map{r($a,$_)}%{$h{$b}}
}
# Did we happen on an inconsistency? Do pigs fly? Dont pigs fly? Maybe (Bitwise or is okay too)
print$e|$h{P}{X}?Yes:$h{P}{NX}?No:Maybe
```
[Answer]
# Haskell, 586 566 547 bytes
I wrote this on the assumption that for every property *P* there must exist some *x* and *y* such that *P(x)* is true and *P(y)* is false; without this assumption, the fourth example input wouldn't have a contradiction and would answer "No".
```
#define X p s q m
#define W where
t=0<1;f=0>1;y="Yes"
l=length;r=filter;h=head;(#)=(,)
u 0=[[]];u n=[x:y|x<-[t,f],y<-u$n-1]
c l=all(==h l)l#and l
X[]|or[fst$c$map(!!(n-1))e|n<-[1..l$h e]]=y|z t=y|z f="No"|t="Maybe"W e=m$u$l s;z m=t#m==(c$map h$q e)
X("Pigs":_:y)=p v((r$(==a).(!!k)).q)m z W((k,v),z,a)=s%y
X(_:_:_:y)=p w q((r(\x->(x!!j/=a)||(x!!k==b))).m)v W((j,u),_:_:z,a)=s%y;((k,w),v,b)=u%z
s%("not":w)=(i,u,not p)W(i,u,p)=s%w
s%(_:"to":_:w)=(0#s,w,t)
s%(w:z)=(maybe(l s,s++[w#l s])(#s)$lookup w s,z,t)
main=interact$p[""#0]id id.words.r(/='.')
```
This should be compiled with the ghc command line option "-cpp". Input must be terminated by EOF (^D). You can try it online at <http://melpon.org/wandbox/>, but you cannot set command line options. Instead, you can prefix the program with the language option
```
{-# LANGUAGE CPP #-}
```
It works by collecting the set of traits, then filtering the set of trait -> truth valuations using the implications in the input. The result is then tested to ensure that every trait can be validly assigned to both True and False (failure here is the *ex falso quodlibet* case). Finally, it looks for valuations which match the pig facts, checking the value for "able to fly" in each valuation.
Quite a few bytes were lost to threading state around: the set of traits seen so far, the pig-fact-selector function, and the filtering function determined by the implications. Probably the exact same idea would be much shorter in an impure language.
*Edit:* Saved several bytes by proud haskeller's suggestion, then a couple extra by replacing the binding of z and "u%drop 2 z" with a binding to "\_ : \_ : z" and "u%z", saving 3.
*Edit 2:* Saved some more. Used the (#)=(,) trick to save 2 bytes and learned about pattern synonyms (<https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms>), but the notation was too verbose to get a savings from eliminating the rest of the pairs in this program. Squeezed out some more savings by changing the patterns that the parser searches for. For example: if a sentence doesn't start with Pigs and we have anything left in the parser state, we parse a "Everything that is.." sentence. This saved lots of characters in the patterns for X and %.
[Answer]
# Python, ~~547~~ ~~536~~ ~~525~~ ~~521~~ ~~513~~ ~~509~~ ~~497~~ ~~503~~ 501
```
m=map
o='not ';R={'':{''}}
S=lambda x,y:filter(len,m(str.strip,x.split(y)))
N=lambda a:[o+a,a[4:]][a[:4]==o]
def C(s):a,c=S(s[19:],'is also');return[(a,c),(N(c),N(a))]
X=lambda A:A&set(m(N,A))and 1/0 or A
for a,c in sum(m(lambda x:[('',x[9:])]if'P'==x[0]else C(x),S(raw_input(),'.')),[]):R.setdefault(a,{a}).add(c)
def F(s):
 i,n={s},{s}
 while 1:
  for r in i:n|=R.get(r,n)
  if X(i)>=n:return i
  i|=n
try:a='able to fly';n=N(a);c={n:'No','':'Maybe'}[''.join({a,n}&m(F,R)[0])]
except:c='Yes'
print c
```
For each `a -> b` in the input, we add the given clause and its negation `not b -> not a` to the set of clauses and then compute the set of propositions that are `->`-reachable from any proposition using a fixpoint loop. Whenever we encounter a contradiction, we throw (and later catch) a `ZeroDivisionError` and print `Yes`.
Finally, we check if 'able to fly' (and/or its negation) is reachable from the 'is pig' proposition `''` and print the appropriate response.
**EDIT**: ~~This is buggy, fixing it.~~ Fixed.
[Answer]
## Ruby 1.9.3 (~~365 364~~ 362)
```
h='able to fly'
i="(not )?(#{h}|\\w+)"
o=->s{n=Regexp.new(i+" (is also|are) "+i).match s
[[n[2],!n[1]],[n[5],!n[4]]]}
c=e=!z=[]
w=->r{z.member?(r)||(z<<(a,b=r)
c|=a[0]==b[0]&&a[1]!=b[1]
w[[[b[0],!b[1]],[a[0],!a[1]]]]
z.map{|q|q[1]==r[0]&&w[[q[0],r[1]]]})}
y=->x{z.member?([[p='Pigs',!e],[h,x]])}
f=->x{x.split(?.).map{|s|w[o[s]]}
c|y[!e]?'Yes':y[e]?'No':'Maybe'}
```
### Usage
The code above defines a function `f`, which takes one parameter representing the textual input and returns `Yes`, `No`, or `Maybe`.
For example: 
```
f['Pigs are old. Everything that is not able to fly is also not old.']
=> "Yes"
```
### Online test: <http://ideone.com/fxLemg>
The ungolfed code (including unit tests) is available [here](https://github.com/clupasq/codegolf/blob/master/35623-pigs-fly/pigs_fly.rb).
]