MCPcopy
hub / github.com/nltk/nltk / _read_partial_featlist

Method _read_partial_featlist

nltk/featstruct.py:2272–2316  ·  view source on GitHub ↗
(self, s, position, match, reentrances, fstruct)

Source from the content-addressed store, hash-verified

2270 return self._read_partial_featlist(s, position, match, reentrances, fstruct)
2271
2272 def _read_partial_featlist(self, s, position, match, reentrances, fstruct):
2273 # Prefix features are not allowed:
2274 if match.group(2):
2275 raise ValueError("open bracket")
2276 # Bare prefixes are not allowed:
2277 if not match.group(3):
2278 raise ValueError("open bracket")
2279
2280 # Build a list of the features defined by the structure.
2281 while position < len(s):
2282 # Check for the close bracket.
2283 match = self._END_FSTRUCT_RE.match(s, position)
2284 if match is not None:
2285 return fstruct, match.end()
2286
2287 # Reentances have the form "-> (target)"
2288 match = self._REENTRANCE_RE.match(s, position)
2289 if match:
2290 position = match.end()
2291 match = self._TARGET_RE.match(s, position)
2292 if not match:
2293 raise ValueError("identifier", position)
2294 target = match.group(1)
2295 if target not in reentrances:
2296 raise ValueError("bound identifier", position)
2297 position = match.end()
2298 fstruct.append(reentrances[target])
2299
2300 # Anything else is a value.
2301 else:
2302 value, position = self._read_value(0, s, position, reentrances)
2303 fstruct.append(value)
2304
2305 # If there's a close bracket, handle it at the top of the loop.
2306 if self._END_FSTRUCT_RE.match(s, position):
2307 continue
2308
2309 # Otherwise, there should be a comma
2310 match = self._COMMA_RE.match(s, position)
2311 if match is None:
2312 raise ValueError("comma", position)
2313 position = match.end()
2314
2315 # We never saw a close bracket.
2316 raise ValueError("close bracket", position)
2317
2318 def _read_partial_featdict(self, s, position, match, reentrances, fstruct):
2319 # If there was a prefix feature, record it.

Callers 1

_read_partialMethod · 0.95

Calls 4

_read_valueMethod · 0.95
matchMethod · 0.45
endMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected