-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_generator.py
126 lines (112 loc) · 5.27 KB
/
text_generator.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
123
124
125
126
from string import Template
def generate_operation(template_operations, operation_type=None, objects=None, no_op=False):
'''
Generates operation texts from templates and returns list.
:param template_operations: List of template operations
:param objects: Object names that need to be inserted
:param operation_type: Class of operation
:return: List of generated operations for operation type
'''
generated_op = ''
generated_ops = []
for op in template_operations:
if operation_type != None:
#Adding operation placeholder at the end of operate template
op = op + ', $operation' + '\n'
s = Template(op)
if not no_op and objects:
for obj in objects:
#Replacing placeholders
generated_op = s.substitute(object=obj, operation=operation_type)
# print(generated_op)
generated_ops.append(generated_op)
else:
generated_op = s.substitute(operation=operation_type)
generated_ops.append(generated_op)
else:
op = op + '\n'
s = Template(op)
for obj in objects:
generated_op = s.substitute(object=obj)
generated_ops.append(generated_op)
return generated_ops
OBJECTS = ['laptop',
'book',
'cup',
'mobile phone',
'pen',
'bottle',
'hand',
'chair',
'mouse',
'monitor',
'keyboard']
locate_operations = ('Find the $object',
'Show me the location of $object',
'Locate the $object',
'Please locate the $object',
'Where is the $object',
'Where are the ${object}s',
'What is the location of $object',
'What are the locations of ${object}s',
'Can you find the $object for me?',
'Point out the $object',
'Detect $object',
'Spot the $object',
'Highlight the $object',
'Color the $object',
'Show me where the $object is',
'Show me where the $object are',
'Detect the $object',
'Search for the $object',
'Find where the $object is',
'Find where the $object are',
'Discover the $object',
'Track the $object',
'Point me the $object',
'Where did I put my $object',
'Where did I keep my $object',
'I need to find my $object',
'Can you help find my $object',
'Help me find my $object',
'Is there a $object here',
'I can’t find my $object')
describe_operations = ('Give me information about the $object',
'Show me the properties of $object',
'Describe $object',
'Give me the details about $object',
'Make me aware of $object',
'Show properties of this $object',
'What are the features of the $object',
'What are the properties of the $object',
'Give a detailed description of $object',
'Give an account of this $object',
'Explain the features of this $object',
'Explain the properties of this $object',
'What is the brand of the $object',
'Who is the manufacturer of $object',
'What kind of $object is this?',
'I want the details of this $object',
'Search the details of this $object',
'Provide the details of this $object',
'Can I know more about the $object',
'Can I get information about the $object',
'What can you say about this $object',
'What do you know about the $object',
'What is this $object',
'Give me the specification of the $object',
'Can you describe this $object')
no_Op_lines = []
for line in open('/home/ashen/Documents/GitHubRepos/pykaldi/examples/setups/zamia/out/test/decode.out', 'r'):
if line.strip():
no_Op_lines.append(line.rstrip('\n'))
# dataset_text_file = open(r'/home/ashen/Documents/Dataset_text_classification.txt', 'w+')
#
# dataset_text_file.writelines(generate_operation(locate_operations, operation_type='1', objects=OBJECTS))
# dataset_text_file.writelines(generate_operation(describe_operations, operation_type='2', objects=OBJECTS))
# dataset_text_file.writelines(generate_operation(no_Op_lines, operation_type='3', no_op=True))
#
# dataset_text_file.close()
with open(r'/home/ashen/Documents/Dataset_AE_positive.txt', 'w+') as f:
f.writelines(generate_operation(locate_operations, objects=OBJECTS))
f.writelines(generate_operation(describe_operations, objects=OBJECTS))