-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_case_and_joiner_rules.py
122 lines (109 loc) · 3.63 KB
/
_case_and_joiner_rules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
print "importing " + __file__
from dragonfly import *
import BaseGrammars
from BaseRules import *
import inspect
grammar = BaseGrammars.ContinuousGrammar("case and joiner rules")
#decorator
def GrammarRule(rule):
if inspect.isclass(rule):
if issubclass(rule, BaseQuickRules):
rule(grammar)
else:
grammar.add_rule(rule())
else:
grammar.add_rule(rule)
@GrammarRule
class CapFirstRule(ContinuousRule):
spec = "capital <RunOn>"
extras = (Dictation("RunOn"),)
def _process_recognition(self, node, extras):
wordOrPhrase = extras["RunOn"].format().capitalize()
Text(wordOrPhrase).execute()
@GrammarRule
class LowerCaseFirstRule(ContinuousRule):
spec = "low case <RunOn>"
extras = (Dictation("RunOn"),)
def _process_recognition(self, node, extras):
wordOrPhrase = extras["RunOn"].format()
if wordOrPhrase:
wordOrPhrase = wordOrPhrase[0].lower() + wordOrPhrase[1:]
Text(wordOrPhrase).execute()
@GrammarRule
class AllLowerCaseRule(ContinuousRule):
spec = "all low case <RunOn>"
extras = (Dictation("RunOn"),)
def _process_recognition(self, node, extras):
wordOrPhrase = extras["RunOn"].format().lower()
if wordOrPhrase:
Text(wordOrPhrase).execute()
@GrammarRule
class LowercaseJoined(ContinuousRule):
spec = "joined <RunOn>"
extras = Dictation("RunOn"),
def _process_recognition(self, node, extras):
Text("".join(extras["RunOn"].words)).execute()
@GrammarRule
class CamelCaseRule(ContinuousRule):
spec = "camel <RunOn>"
extras = Dictation("RunOn"),
def _process_recognition(self, node, extras):
msg = extras["RunOn"].format()
msg = msg.lower()
wrds = msg.split(" ")
for i, word in enumerate(wrds):
if i > 0:
if len(word) > 1:
wrds[i] = word[0].upper() + word[1:]
else:
wrds[i] = word.upper()
Text("".join(wrds)).execute()
@GrammarRule
class TitleCaseRule(ContinuousRule):
spec = "title <RunOn>"
extras = Dictation("RunOn"),
def _process_recognition(self, node, extras):
msg = extras["RunOn"].format()
wrds = msg.split(" ")
for i, word in enumerate(wrds):
if len(word) > 1:
wrds[i] = word[0].upper() + word[1:]
else:
wrds[i] = word.upper()
Text(" ".join(wrds)).execute()
@GrammarRule
class ClassicConstantVariableCaseRule(ContinuousRule):
spec = "constant <RunOn>"
extras = Dictation("RunOn"),
def _process_recognition(self, node, extras):
msg = extras["RunOn"].format()
wrds = msg.split(" ")
for i, word in enumerate(wrds):
wrds[i] = word.upper()
Text("_".join(wrds)).execute()
@GrammarRule
class CapitalCamelCaseRule(ContinuousRule):
spec = "(capital camel|pillar) <RunOn>"
extras = Dictation("RunOn"),
def _process_recognition(self, node, extras):
msg = extras["RunOn"].format()
msg = msg.lower()
wrds = msg.split(" ")
for i, word in enumerate(wrds):
if len(word) > 1:
wrds[i] = word[0].upper() + word[1:]
else:
wrds[i] = word.upper()
Text("".join(wrds)).execute()
@GrammarRule
class UnderscoreJoinedTextRule(ContinuousRule):
spec = "scored <RunOn>"
extras = (Dictation("RunOn"),)
def _process_recognition(self, node, extras):
Text("_".join(extras["RunOn"].words)).execute()
grammar.load()
def unload():
global grammar
if grammar:
grammar.unload()
grammar = None