Write `collection/{file_name}.xml` with `file_name` as the collection `id`, `coll_name` as the collection `name`, and `items` as a list of collection items. :param file_name: The id of the collection, equivalent to the file name, e.g. `all-corpora`. :type file_name: str :par
(file_name: str, coll_name: str, items: List[str])
| 14 | ROOT = sys.argv[1] |
| 15 | |
| 16 | def write(file_name: str, coll_name: str, items: List[str]) -> None: |
| 17 | """Write `collection/{file_name}.xml` with `file_name` as the collection `id`, |
| 18 | `coll_name` as the collection `name`, and `items` as a list of collection items. |
| 19 | |
| 20 | :param file_name: The id of the collection, equivalent to the file name, |
| 21 | e.g. `all-corpora`. |
| 22 | :type file_name: str |
| 23 | :param coll_name: The name of the collection, e.g. `"All corpora"` |
| 24 | :type coll_name: str |
| 25 | :param items: A list of names for the collection items, e.g. `["abc", "alpino", ...]` |
| 26 | :type items: List[str] |
| 27 | """ |
| 28 | et = ElementTree.Element("collection", id=file_name, name=coll_name) |
| 29 | et.extend(ElementTree.Element("item", ref=item) for item in sorted(items)) |
| 30 | _indent_xml(et) |
| 31 | with open(os.path.join(ROOT, "collections", file_name + ".xml"), "w", encoding="utf8") as f: |
| 32 | f.write(ElementTree.tostring(et).decode("utf8")) |
| 33 | |
| 34 | def get_id(xml_path: str) -> str: |
| 35 | """Given a full path, extract only the filename (i.e. the nltk_data id) |