This file is indexed.

/usr/share/pyshared/frog/csiparse2.py is in frog 0.12.17-7.1+b1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python

"""
Generate instances for the pairwise dependency prediction task.

usage: %prog [options] [file...]

-mDIST, --max-dist=DIST: maximum distance between head and dependent

---
:Refinements:
-m: type='int', dest='maxDist'
"""

import fileinput

from itertools import imap, izip

from sentences import sentenceIterator

import common
import deptree


def list_rindex(lst, x):
	for i in xrange(len(lst) - 1, -1, -1):
		if lst[i] == x:
			return i
	raise ValueError("")


def parseDist(string):
	dist = dict((label.strip(), float(weight))
				for label, weight in map(str.split, string.strip().split(",")))
	normFactor = sum(dist.itervalues())
	for cls, weight in dist.iteritems():
		dist[cls] = weight / normFactor
	
	return dist


def parseInstanceLine(line):
	instance = line.split()
	startIndex = list_rindex(instance, "{")
	endIndex = instance.index("}", startIndex)
	dist = parseDist(" ".join(instance[startIndex:endIndex]).strip("{}"))
	return instance[:startIndex], dist, 0 #float(instance[endIndex+1])


def instanceIterator(stream):
	return imap(parseInstanceLine, stream)


def formulateWCSP(sentence, dirInstances,
				  relInstances, pairInstances,
				  options):
	domains = [None] + [[] for token in sentence]
	constraints = []

	for dependent in sentence:
		dependentId = int(dependent[0])
		headId = 0
		instance, distribution, distance = pairInstances.next()

		cls = instance[-1]
		conf = distribution[cls]

		if cls != "__":
			constraints.append(deptree.HasDependency(dependentId,
													 headId, cls,
													 conf))
		if cls != "__":
			domains[dependentId].append((headId, cls))

	for dependent, head in common.pairIterator(sentence, options):
		dependentId = int(dependent[0])
		headId = int(head[0])

		instance, distribution, distance = pairInstances.next()

		cls = instance[-1]
		conf = distribution[cls]
		#conf = sum(distribution[x] for x in distribution if x != "__")

		#if distance == 0:
		#	conf = 1000000
		#else:
		#	conf = 1.0 / distance

		#constraints.append(deptree.HasDependency(dependentId,
		#										 headId, cls,
		#										 conf))
		if cls != "__":
			constraints.append(deptree.HasDependency(dependentId,
													 headId, cls,
													 conf))
		if cls != "__":
			domains[dependentId].append((headId, cls))


	if dirInstances:
		for token, (instance, distribution, distance) in izip(sentence,
															  dirInstances):
			tokenId = int(token[0])
			cls = instance[-1]
			if True: #cls != "__":
				#constraints.append(deptree.DependencyDirection(
				#	tokenId,
				#	getattr(deptree.DependencyDirection, cls),
				#	distribution[cls]))

				for cls in distribution:
					constraints.append(deptree.DependencyDirection(
						tokenId,
						getattr(deptree.DependencyDirection, cls),
						distribution[cls]))

				#if "__" in distribution:
				#	constraints.append(deptree.DependencyDirection(
				#		tokenId, 100, distribution["__"]))
				#if "RIGHT" in distribution:
				#	cls = "RIGHT"
				#	constraints.append(deptree.DependencyDirection(
				#		tokenId,
				#		getattr(deptree.DependencyDirection, cls),
				#		distribution[cls]))
				#if "LEFT" in distribution:
				#	cls = "LEFT"
				#	constraints.append(deptree.DependencyDirection(
				#		tokenId,
				#		getattr(deptree.DependencyDirection, cls),
				#		distribution[cls]))
			#else:
			#	constraints.append(deptree.DependencyDirection(
			#		tokenId, deptree.DependencyDirection.LEFT,
			#		-distribution[cls]))
			#	constraints.append(deptree.DependencyDirection(
			#		tokenId, deptree.DependencyDirection.RIGHT,
			#		-distribution[cls]))

	if relInstances:
		for token, (instance, distribution, distance) in izip(sentence,
															  relInstances):
			tokenId = int(token[0])
			cls = instance[-1]

			distribution = dict((tuple(key.split("|")), value)
								for key, value
								in distribution.iteritems())

			if cls != "__":
				for rel in cls.split("|"):
					conf = sum(value
							   for key, value
							   in distribution.iteritems()
							   if rel in key)

					constraints.append(deptree.HasIncomingRel(tokenId,
															  rel,
															  conf))


	return domains, constraints


def main(options, args):
	dirOutput, relsOutput, pairsOutput = args[:3]

	dirStream = open(dirOutput)
	relsStream = open(relsOutput)
	pairsStream = open(pairsOutput)

	dirIterator = instanceIterator(dirStream)
	relsIterator = instanceIterator(relsStream)
	pairsIterator = instanceIterator(pairsStream)
	
	for sentence in sentenceIterator(fileinput.input(args[3:])):
		csp = formulateWCSP(sentence,
							dirIterator,
							relsIterator,
							pairsIterator,
							options)


	dirStream.close()
	relsStream.close()
	pairsStream.close()


if __name__ == "__main__":
	import cmdline
	main(*cmdline.parse())