-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:aymara/lima
- Loading branch information
Showing
8 changed files
with
252 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2002-2024 CEA LIST | ||
# SPDX-FileCopyrightText: 2024 CEA LIST <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
############################################### | ||
# Categories conversion program : | ||
# converts dicostd into dicojys (data multiplicative coding) | ||
############################################### | ||
|
||
import argparse | ||
import sys | ||
|
||
from tqdm import tqdm | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Convert dicostd into dicojys.") | ||
parser.add_argument("source", type=str, help="Source file") | ||
parser.add_argument("convert", type=str, help="Convert file") | ||
parser.add_argument("cible", type=str, help="Cible file") | ||
|
||
args = parser.parse_args() | ||
|
||
print("INFO : Start default categories conversion", file=sys.stderr) | ||
|
||
try: | ||
source = open(args.source, "r", encoding="utf-8") | ||
except IOError: | ||
print(f"Cannot open {args.source}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
try: | ||
convert = open(args.convert, "r", encoding="utf-8") | ||
except IOError: | ||
print(f"Cannot open {args.convert}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
try: | ||
cible = open(args.cible, "w", encoding="utf-8") | ||
except IOError: | ||
print(f"Cannot open {args.cible}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
try: | ||
error = open("error.txt", "a", encoding="utf-8") | ||
except IOError: | ||
print("Cannot open error.txt", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
tags = {} | ||
for line in convert: | ||
donneestags = line.strip().split(";") | ||
if len(donneestags) > 1: | ||
tags[donneestags[0]] = donneestags[1] | ||
|
||
convert.close() | ||
|
||
line_num = 0 | ||
|
||
source_lines = source.readlines() | ||
for line in tqdm(source_lines, desc="Processing lines", unit="line"): | ||
line_num += 1 | ||
line = line.strip() | ||
if len(line) == 0 or line.startswith("#"): | ||
continue | ||
|
||
donnees = line.split("\t") | ||
if len(donnees) != 2: | ||
error_message = ( | ||
f"in file {args.source} line {line_num}: " | ||
f"wrong number of columns. Ignore line: {line}\n" | ||
) | ||
print(error_message, file=sys.stderr) | ||
error.write(error_message) | ||
continue | ||
|
||
type_ = donnees[0] | ||
info = donnees[1] | ||
|
||
if info in tags and tags[info]: | ||
cible.write(f"{type_}\t{tags[info]}\n") | ||
else: | ||
error_message = ( | ||
f"in file {args.source} line {line_num}: " | ||
f"Invalid properties {type_} {info}\n" | ||
) | ||
print(error_message, file=sys.stderr) | ||
error.write(error_message) | ||
|
||
source.close() | ||
cible.close() | ||
error.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2002-2024 CEA LIST | ||
# SPDX-FileCopyrightText: 2024 CEA LIST <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import argparse | ||
import codecs | ||
|
||
from tqdm import tqdm | ||
|
||
|
||
def print_usage(): | ||
print("USAGE : xmlforms [OPTIONS] inputfile outputfile") | ||
print("where [OPTIONS] are :") | ||
print(" -h or -help : print usage") | ||
print( | ||
" -desacc=[yes|no] : specify desacc attribute for entries. " | ||
"default is none, that equals 'yes'" | ||
) | ||
print( | ||
" -entryop=[add|replace|delete] : specify op attribute for entries. " | ||
"default is none, that equals 'add'" | ||
) | ||
print( | ||
" -lingop=[add|replace|delete] : specify op attribute for linginfos. " | ||
"default is none, that equals 'add'" | ||
) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Process input and output files with options." | ||
) | ||
parser.add_argument("inputfile", type=str, help="Input file") | ||
parser.add_argument("outputfile", type=str, help="Output file") | ||
parser.add_argument( | ||
"-desacc", | ||
type=str, | ||
choices=["yes", "no"], | ||
help="Specify desacc attribute for entries. " | ||
'Default is none, that equals "yes"', | ||
) | ||
parser.add_argument( | ||
"-entryop", | ||
type=str, | ||
choices=["add", "replace", "delete"], | ||
help="Specify op attribute for entries. " 'Default is none, that equals "add"', | ||
) | ||
parser.add_argument( | ||
"-lingop", | ||
type=str, | ||
choices=["add", "replace", "delete"], | ||
help="Specify op attribute for linginfos. " | ||
'Default is none, that equals "add"', | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
with ( | ||
codecs.open(args.inputfile, "r", "utf-8") as source, | ||
codecs.open(args.outputfile, "a", "utf-8") as out | ||
): | ||
form = "" | ||
lemma = "" | ||
norm = "" | ||
|
||
count = 0 | ||
icount = 0 | ||
|
||
lines = source.readlines() | ||
for line in tqdm(lines, desc="Processing lines", unit="line"): | ||
line = line.strip() | ||
line = ( | ||
line.replace("&", "&") | ||
.replace('"', """) | ||
.replace("<", "<") | ||
.replace(">", ">") | ||
) | ||
if line == "": | ||
continue | ||
|
||
line = line.split("#")[0].strip() | ||
data = line.split("\t") | ||
if line == "" or len(data) != 4: | ||
print(f"xmlform: Invalid line '{line}'") | ||
continue | ||
|
||
if data[0] != form: | ||
form = data[0] | ||
if count > 0: | ||
out.write(" </i>\n</entry>\n") | ||
out.write(f'<entry k="{form}"') | ||
if args.desacc: | ||
out.write(f' desacc="{args.desacc}"') | ||
if args.entryop: | ||
out.write(f' op="{args.entryop}"') | ||
out.write(">\n") | ||
icount = 0 | ||
count += 1 | ||
|
||
if icount == 0 or data[1] != lemma or data[2] != norm: | ||
lemma = data[1] | ||
norm = data[2] | ||
if icount > 0: | ||
out.write(" </i>\n") | ||
out.write(" <i") | ||
if lemma: | ||
out.write(f' l="{lemma}"') | ||
if norm: | ||
out.write(f' n="{norm}"') | ||
if args.lingop: | ||
out.write(f' op="{args.lingop}"') | ||
out.write(">\n") | ||
icount += 1 | ||
|
||
out.write(f' <p v="{data[3]}"/>\n') | ||
|
||
if count > 0: | ||
out.write(" </i>\n</entry>\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |