onlinejudge_template.analyzer.simple_patterns module

the module to guess simple format trees from sample strings

この module はサンプル文字列から直接 (つまり、フォーマット文字列を用いずに) 典型的なフォーマット木を推測します。利用可能なサンプル文字列の個数がひとつしかない場合での利用が想定されています。 単純なフォーマット木を列挙しておき、それらとのパターンマッチをすることによって実装されています。

たとえば

6
1 3 8 7 10 2

というサンプル文字列から

sequence([
    item("N"),
    newline(),
    loop(counter="i", size="N",
        item("A", indices="i")
    ),
    newline(),
])

のようなフォーマット木 (FormatNode) を作ります。

exception onlinejudge_template.analyzer.simple_patterns.SimplePatternMatchingError[source]

Bases: onlinejudge_template.types.AnalyzerError

onlinejudge_template.analyzer.simple_patterns.guess_format_with_pattern_matching(*, instances: List[str]) → Optional[onlinejudge_template.types.FormatNode][source]

guess_format_with_pattern_matching guesses a format tree from the strings which match with the format tree, i.e. sample cases.

Parameters:instances – are sample cases.
onlinejudge_template.analyzer.simple_patterns.guess_output_format_with_pattern_matching_using_input_format(*, instances: List[onlinejudge_template.types.SampleCase], input_format: onlinejudge_template.types.FormatNode, input_variables: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarDecl]) → Optional[onlinejudge_template.types.FormatNode][source]
Parameters:
  • instances – are sample cases.
  • input_format
  • input_variables
onlinejudge_template.analyzer.simple_patterns.list_all_patterns[source]

list_all_patterns lists all pre-defined petterns.

onlinejudge_template.analyzer.simple_patterns.list_output_patterns_depending_input_variable(n: str) → List[onlinejudge_template.types.FormatNode][source]

list_output_patterns_depending_input_variable lists output patterns which depend input patterns.

Parameters:n – is the name of the variable which represents the length of array.
onlinejudge_template.analyzer.simple_patterns.rename_variables_if_conflicts(node: onlinejudge_template.types.FormatNode, *, env: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarDecl]) → onlinejudge_template.types.FormatNode[source]