Esempio n. 1
0
def makeContextualRule(name,
                       mapping,
                       extras=[],
                       defaults={},
                       ruleType=RuleType.SERIES,
                       seriesMergeGroup=0):
    x = makeHashedRule(name, mapping, extras, defaults, ruleType,
                       seriesMergeGroup)
    return ContextualRule(x)
Esempio n. 2
0
    def _buildRule(self):                
        mapping = {}
        for command in self.cmdWords:
            mapping[command] = None
        self.actionRule = makeHashedRule(self._actionRuleName, mapping, ruleType=RuleType.INDEPENDENT)
        pushEvent(RuleRegisterEvent(self.actionRule))

        mapping = {}
        extras = []
        for i in range(self.MAX_SUBWORDS):
            for j in range(i+1):
                phrase = []
                for k in range(j, self.MAX_SUBWORDS):
                    optional = (k != j)
                    refString = "<" + self._wordListRefName(i, k) + ">"
                    if optional:
                        refString = "[%s]" % refString
                    phrase.append(refString)
                    extras.append(ListRef(self._wordListName(i, k), self._wordListRefName(i, k), []))
                phrase = " ".join(phrase)
                mapping[phrase] = None                
        
        self.wordRule = makeHashedRule(self._wordRuleName, mapping, extras, ruleType=RuleType.INDEPENDENT)
        pushEvent(RuleRegisterEvent(self.wordRule))

        wordRulePart = "<%s>" % self._wordRuleRefName
        if self.allowNoChoice:
           wordRulePart = "[%s]" % wordRulePart 

        phrase = ("<%s>" % self._actionRuleRefName) + " " + wordRulePart
        mapping = {
            phrase : self._onSelection
        }
        extras = [
            RuleRef(self.actionRule, self._actionRuleRefName),
            RuleRef(self.wordRule, self._wordRuleRefName),
        ]

        self.rule = makeContextualRule(self._ruleName, mapping, extras, ruleType=self.ruleType)

        log.info("new crazy rule: [%s]" % self.rule.rule.rule.mapping)
        log.info("new crazy rule extras: [%s]" % self.rule.rule.rule.extras)
Esempio n. 3
0
from rules.ContextualRule import makeContextualRule
from requirements.Emacs import IsEmacs
from requirements.VarRequirement import VarRequirement
from rules.emacs.common import emacsExtras, emacsDefaults

_mapping = {
    "red": "red",
    "green": "green",
    "white": "white",
    "purple": "purple",
    "yellow": "yellow",
    "orange": "orange",
}

ColorRule = makeHashedRule("ColorRule",
                           _mapping,
                           ruleType=RuleType.INDEPENDENT)
pushEvent(RuleRegisterEvent(ColorRule))

_mapping = {
    "circle": 0x030a,
    "corner": 0x031a,
    "hair": 0x030f,
}

AccentRule = makeHashedRule("AccentRule",
                            _mapping,
                            ruleType=RuleType.INDEPENDENT)
pushEvent(RuleRegisterEvent(AccentRule))

Esempio n. 4
0
    "knave" : "n",
    "osh"   : "o",
    "pig"   : "p",
    "quid"  : "q",
    "robe"  : "r",
    "shoe"  : "s",
    "toss"  : "t",
    "use"   : "u",
    "vict"  : "v",
    "was"   : "w",
    "xray"  : "x",
    "yes"   : "y",
    "zulu"  : "z",
}

AlphaRule = makeHashedRule("AlphaRule", _mapping, ruleType=RuleType.INDEPENDENT)
pushEvent(RuleRegisterEvent(AlphaRule))

_mapping = {
    "zero"  : "0",
    "one"   : "1",
    "two"   : "2",
    "three" : "3",
    "four"  : "4",
    "five"  : "5",
    "six"   : "6",
    "seven" : "7",
    "eight" : "8",
    "nine"  : "9",
}
Esempio n. 5
0
    "knave" : "n",
    "osh"   : "o",
    "pig"   : "p",
    "quid"  : "q",
    "road"  : "r",
    "shoe"  : "s",
    "toss"  : "t",
    "use"   : "u",
    "vict"  : "v",
    "was"   : "w",
    "xray"  : "x",
    "yes"   : "y",
    "zulu"  : "z",
}

AlphaRule = makeHashedRule("AlphaRule", _mapping, ruleType=RuleType.INDEPENDENT)
pushEvent(RuleRegisterEvent(AlphaRule))

_mapping = {
    "zero"  : "0",
    "one"   : "1",
    "two"   : "2",
    "three" : "3",
    "four"  : "4",
    "five"  : "5",
    "six"   : "6",
    "seven" : "7",
    "eight" : "8",
    "nine"  : "9",
}
Esempio n. 6
0
def makeContextualRule(name, mapping, extras=[], defaults={}, ruleType=RuleType.SERIES,
                       seriesMergeGroup=0):
    x = makeHashedRule(name, mapping, extras, defaults, ruleType, seriesMergeGroup)
    return ContextualRule(x)
Esempio n. 7
0
def makeKeywordListRule(name, keywords):
    keywords = normalizeKeywords(keywords)
    _mapping = {k[1]: k[0] for k in keywords}
    return makeHashedRule(name, _mapping, ruleType=RuleType.INDEPENDENT)
Esempio n. 8
0
from rules.ContextualRule import makeContextualRule
from requirements.Emacs import IsEmacs
from requirements.ModeRequirement import ModeRequirement
from rules.emacs.Cmd import Cmd, runEmacsCmd
from rules.emacs.Text import EmacsText
from protocol import makeHashedRule, RuleType, RuleRef
from EventLoop import pushEvent
from EventList import RuleRegisterEvent

_mapping = {
    "key": None,
    "doog key": None,
    "go key": None,
}

VerbRule = makeHashedRule("VerbRule", _mapping, ruleType=RuleType.INDEPENDENT)
pushEvent(RuleRegisterEvent(VerbRule))


class KeywordCmd(Cmd):
    def __init__(self, keywords, verbRule, kwRule, log=False):
        self.writtenForms = {}
        self.verbRule = verbRule
        self.kwRule = kwRule
        for i in keywords:
            self.writtenForms[i[1]] = i[0]
        Cmd.__init__(self, None, log)

    def _lisp(self, extras={}):
        command = " ".join(extras[self.verbRule]['words'])
        spokenKeyword = " ".join(extras[self.kwRule]['words'])