MCPcopy Index your code
hub / github.com/clips/pattern / conditional

Function conditional

pattern/text/en/modality.py:94–133  ·  view source on GitHub ↗

The conditional mood is used to talk about possible or imaginary situations. It is marked by the infinitive form of the verb, preceded by would/could/should: "we should be going", "we could have stayed longer". With predictive=False, sentences with will/shall need an explici

(sentence, predictive=True, **kwargs)

Source from the content-addressed store, hash-verified

92# print
93
94def conditional(sentence, predictive=True, **kwargs):
95 """ The conditional mood is used to talk about possible or imaginary situations.
96 It is marked by the infinitive form of the verb, preceded by would/could/should:
97 "we should be going", "we could have stayed longer".
98 With predictive=False, sentences with will/shall need an explicit if/when/once-clause:
99 - "I will help you" => predictive.
100 - "I will help you if you pay me" => speculative.
101 Sentences with can/may always need an explicit if-clause.
102 """
103 S = sentence
104 if not (hasattr(S, "words") and hasattr(S, "parse_token")):
105 raise TypeError, "%s object is not a parsed Sentence" % repr(S.__class__.__name__)
106 if question(S):
107 return False
108 i = find(lambda w: s(w) == "were", S)
109 i = i and i.index or 0
110 if i > 0 and (s(S[i-1]) in ("i", "it", "he", "she") or S[i-1].type == "NN"):
111 # "As if it were summer already." => subjunctive (wish).
112 return False
113 for i, w in enumerate(S):
114 if w.type == "MD":
115 if s(w) == "ought" and i < len(S) and s(S[i+1]) == "to":
116 # "I ought to help you."
117 return True
118 if s(w) in ("would", "should", "'d", "could", "might"):
119 # "I could help you."
120 return True
121 if s(w) in ("will", "shall", "'ll") and i > 0 and s(S[i-1]) == "you" and not verbs(S,0,i):
122 # "You will help me." => imperative.
123 return False
124 if s(w) in ("will", "shall", "'ll") and predictive:
125 # "I will help you." => predictive.
126 return True
127 if s(w) in ("will", "shall", "'ll", "can", "may"):
128 # "I will help you when I get back." => speculative.
129 r = s(S).rstrip(" .!")
130 for cc in ("if", "when", "once", "as soon as", "assuming", "provided that", "given that"):
131 if cc+" " in r:
132 return True
133 return False
134
135#from __init__ import parse, Sentence
136#

Callers 2

test_conditionalMethod · 0.90
moodFunction · 0.85

Calls 5

questionFunction · 0.85
sFunction · 0.85
lenFunction · 0.85
verbsFunction · 0.85
findFunction · 0.70

Tested by 1

test_conditionalMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…