Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if __name__ == '__main__':
parser = argparse.ArgumentParser('show diffs between the structures of two CCG trees')
parser.add_argument('file1')
parser.add_argument('file2', nargs='?', default=None)
parser.add_argument('--max-output-num', default=50, type=int)
parser.add_argument('--sampling', default='head', choices=['head', 'tail', 'random'])
args = parser.parse_args()
if args.file2:
file1_trees = [(args.file1, tree) for _, _, tree in read_trees_guess_extension(args.file1)]
file2_trees = [(args.file2, tree) for _, _, tree in read_trees_guess_extension(args.file2)]
assert len(file1_trees) == len(file2_trees)
tree_pairs = list(zip(file1_trees, file2_trees))
else:
file1_trees = ((args.file1, tree) for _, tree in read_trees_guess_extension(args.file1))
tree_pairs = list(zip(file1_trees, file1_trees))
print(to_diffs(tree_pairs, args.max_output_num, args.sampling))
mathml_html = to_mathml([nbest])
with (out_directory / filename).open('w') as f:
print(mathml_html, file=f)
words = nbest[0][0].word if isinstance(nbest[0], tuple) else nbest[0].word
trs.append(f'{i}<a href="{filename}">{filename}</a>{words}')
with (out_directory / 'index.html').open('w') as f:
print(index_html.format('\n'.join(trs)), file=f)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('PATH', help='path to either of *.auto, *.xml, *.jigg.xml, *.ptb')
parser.add_argument('--mkdir', default=None, help='if specified, creates a directory')
args = parser.parse_args()
trees = [[tree] for _, _, tree in read_trees_guess_extension(args.PATH)]
if not args.mkdir:
print(to_mathml(trees))
else:
to_mathml_separate_files(trees, args.mkdir)
parser.add_argument('--annotator',
default='spacy',
choices=english_annotator.keys(),
help='annotate POS, named entity, and lemmas using this library')
parser.add_argument('-f',
'--format',
default='xml',
choices=['auto', 'xml', 'prolog', 'jigg_xml', 'jigg_xml_ccg2lambda', 'json'],
help='output format')
parser.add_argument('--semantic-templates',
help='semantic templates used in "ccg2lambda" format output')
args = parser.parse_args()
annotate_fun = english_annotator[args.annotator]
doc, trees = [], []
for _, tokens, tree in read_trees_guess_extension(args.PATH):
doc.append([token.word for token in tokens])
trees.append([(tree, 0)])
tagged_doc = annotate_fun(doc, tokenize=False)
semantic_templates = args.semantic_templates or SEMANTIC_TEMPLATES[LANG]
print_(trees,
tagged_doc,
format=args.format,
lang=LANG,
semantic_templates=semantic_templates)
parser.add_argument('--annotator',
default='janome',
choices=japanese_annotator.keys(),
help='annotate POS, named entity, and lemmas using this library')
parser.add_argument('-f',
'--format',
default='jigg_xml',
choices=['prolog', 'jigg_xml', 'jigg_xml_ccg2lambda', 'json', 'deriv'],
help='output format')
parser.add_argument('--semantic-templates',
help='semantic templates used in "ccg2lambda" format output')
args = parser.parse_args()
annotate_fun = japanese_annotator[args.annotator]
doc, trees = [], []
for _, tokens, tree in read_trees_guess_extension(args.PATH, lang='ja'):
doc.append(tokens)
trees.append([(tree, 0)])
semantic_templates = args.semantic_templates or SEMANTIC_TEMPLATES[LANG]
print_(trees,
doc,
format=args.format,
lang=LANG,
semantic_templates=semantic_templates)
result += f'<p><strong>{name1}</strong> ID={i}: {tree1.word}</p>'
result += f'<math xmlns="http://www.w3.org/1998/Math/MathML">{tree1_str}</math>'
result += f'<p><strong>{name2}</strong> ID={i}: {tree2.word}</p>'
result += f'<math xmlns="http://www.w3.org/1998/Math/MathML">{tree2_str}</math>'
return MATHML_MAIN.format(result)
if __name__ == '__main__':
parser = argparse.ArgumentParser('show diffs between the structures of two CCG trees')
parser.add_argument('file1')
parser.add_argument('file2', nargs='?', default=None)
parser.add_argument('--max-output-num', default=50, type=int)
parser.add_argument('--sampling', default='head', choices=['head', 'tail', 'random'])
args = parser.parse_args()
if args.file2:
file1_trees = [(args.file1, tree) for _, _, tree in read_trees_guess_extension(args.file1)]
file2_trees = [(args.file2, tree) for _, _, tree in read_trees_guess_extension(args.file2)]
assert len(file1_trees) == len(file2_trees)
tree_pairs = list(zip(file1_trees, file2_trees))
else:
file1_trees = ((args.file1, tree) for _, tree in read_trees_guess_extension(args.file1))
tree_pairs = list(zip(file1_trees, file1_trees))
print(to_diffs(tree_pairs, args.max_output_num, args.sampling))
result += f'<math xmlns="http://www.w3.org/1998/Math/MathML">{tree1_str}</math>'
result += f'<p><strong>{name2}</strong> ID={i}: {tree2.word}</p>'
result += f'<math xmlns="http://www.w3.org/1998/Math/MathML">{tree2_str}</math>'
return MATHML_MAIN.format(result)
if __name__ == '__main__':
parser = argparse.ArgumentParser('show diffs between the structures of two CCG trees')
parser.add_argument('file1')
parser.add_argument('file2', nargs='?', default=None)
parser.add_argument('--max-output-num', default=50, type=int)
parser.add_argument('--sampling', default='head', choices=['head', 'tail', 'random'])
args = parser.parse_args()
if args.file2:
file1_trees = [(args.file1, tree) for _, _, tree in read_trees_guess_extension(args.file1)]
file2_trees = [(args.file2, tree) for _, _, tree in read_trees_guess_extension(args.file2)]
assert len(file1_trees) == len(file2_trees)
tree_pairs = list(zip(file1_trees, file2_trees))
else:
file1_trees = ((args.file1, tree) for _, tree in read_trees_guess_extension(args.file1))
tree_pairs = list(zip(file1_trees, file1_trees))
print(to_diffs(tree_pairs, args.max_output_num, args.sampling))