glazing.framenet.converter¶
Converting FrameNet XML to JSON Lines.
converter
¶
FrameNet XML to JSON Lines converter.
This module provides conversion from FrameNet XML format to JSON Lines format using the glazing FrameNet models. Supports both full frame files and lu files.
| CLASS | DESCRIPTION |
|---|---|
FrameNetConverter |
Convert FrameNet XML files to JSON Lines format. |
| FUNCTION | DESCRIPTION |
|---|---|
convert_frame_file |
Convert a single frame XML file to Frame model. |
convert_lu_file |
Convert a single lexical unit XML file to LexicalUnit model. |
convert_frames_directory |
Convert all frame files in a directory to JSON Lines. |
Examples:
>>> from pathlib import Path
>>> from glazing.framenet.converter import FrameNetConverter
>>> converter = FrameNetConverter()
>>> frame = converter.convert_frame_file("frame/Abandonment.xml")
>>> print(frame.name)
'Abandonment'
>>> # Convert entire directory
>>> converter.convert_frames_directory(
... input_dir="framenet_v17/frame",
... output_file="frames.jsonl"
... )
Classes¶
FrameNetConverter(namespace: str = 'http://framenet.icsi.berkeley.edu', validate_schema: bool = False)
¶
Convert FrameNet XML files to JSON Lines format.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
FrameNet XML namespace URI.
TYPE:
|
validate_schema
|
Whether to validate against DTD/XSD.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
namespace |
FrameNet XML namespace.
TYPE:
|
ns |
Namespace mapping for XPath.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
convert_frame_file |
Convert a frame XML file to Frame model. |
convert_lu_file |
Convert a lexical unit XML file to LexicalUnit model. |
convert_frames_directory |
Convert all frames in a directory to JSON Lines. |
convert_frame_relations_file |
Convert frRelation.xml to frame relation mappings. |
convert_semtypes_file |
Convert semTypes.xml to JSON Lines. |
convert_fulltext_file |
Convert a fulltext XML file to Sentence models. |
convert_fulltext_directory |
Convert all fulltext files in a directory to JSON Lines. |
Initialize the converter.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
FrameNet XML namespace URI.
TYPE:
|
validate_schema
|
Whether to validate XML against schema.
TYPE:
|
Source code in src/glazing/framenet/converter.py
Functions¶
convert_frame_file(filepath: Path | str) -> Frame
¶
Convert a frame XML file to Frame model.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to frame XML file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Frame
|
Parsed Frame model instance. |
Examples:
>>> converter = FrameNetConverter()
>>> frame = converter.convert_frame_file("frame/Abandonment.xml")
>>> print(f"Frame: {frame.name} (ID: {frame.id})")
'Frame: Abandonment (ID: 2031)'
Source code in src/glazing/framenet/converter.py
convert_frame_relations_file(filepath: Path | str) -> dict[int, list[FrameRelation]]
¶
Convert frRelation.xml to frame relation mappings.
Parses the frame relation types and individual frame relations, creating FrameRelation objects grouped by frame ID.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to frRelation.xml file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[int, list[FrameRelation]]
|
Dictionary mapping frame IDs to their FrameRelation objects. |
Examples:
>>> converter = FrameNetConverter()
>>> relations = converter.convert_frame_relations_file("frRelation.xml")
>>> print(f"Found relations for {len(relations)} frames")
Source code in src/glazing/framenet/converter.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
convert_frames_directory(input_dir: Path | str, output_file: Path | str, pattern: str = '*.xml') -> int
¶
Convert all frame files in a directory to JSON Lines with lexical units.
This method parses frame XML files and associates them with lexical units from luIndex.xml (expected to be in the parent directory of input_dir). It also loads frame relations from frRelation.xml and enriches LUs with valence patterns and semantic types from individual lu/*.xml files.
| PARAMETER | DESCRIPTION |
|---|---|
input_dir
|
Directory containing frame XML files.
TYPE:
|
output_file
|
Output JSON Lines file path.
TYPE:
|
pattern
|
File pattern to match.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of frames converted. |
Examples:
>>> converter = FrameNetConverter()
>>> count = converter.convert_frames_directory(
... "framenet_v17/frame",
... "frames.jsonl"
... )
>>> print(f"Converted {count} frames")
'Converted 1221 frames'
Source code in src/glazing/framenet/converter.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 | |
convert_fulltext_directory(input_dir: Path | str, output_file: Path | str, pattern: str = '*.xml') -> int
¶
Convert all fulltext files in a directory to JSON Lines.
| PARAMETER | DESCRIPTION |
|---|---|
input_dir
|
Directory containing fulltext XML files.
TYPE:
|
output_file
|
Output JSON Lines file path.
TYPE:
|
pattern
|
File pattern to match.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of sentences converted. |
Examples:
>>> converter = FrameNetConverter()
>>> count = converter.convert_fulltext_directory(
... "framenet_v17/fulltext",
... "fulltext.jsonl"
... )
>>> print(f"Converted {count} sentences")
Source code in src/glazing/framenet/converter.py
convert_fulltext_file(filepath: Path | str) -> list[Sentence]
¶
Convert a fulltext/*.xml file to Sentence models.
Parses annotated corpus sentences with their annotation sets, layers, and labels.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to fulltext XML file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Sentence]
|
List of parsed Sentence models. |
Examples:
>>> converter = FrameNetConverter()
>>> sentences = converter.convert_fulltext_file("fulltext/ANC__110CYL067.xml")
>>> print(f"Found {len(sentences)} sentences")
Source code in src/glazing/framenet/converter.py
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 | |
convert_lu_file(filepath: Path | str) -> tuple[list[ValencePattern], list[SemTypeRef], list[AnnotationSet]]
¶
Convert an individual lu/*.xml file to extract valence patterns and semtypes.
Parses valence patterns (FE realizations and their syntactic patterns), semantic type references, and annotation sets from a lexical unit file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to individual lu XML file (e.g., lu/lu10.xml).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[ValencePattern], list[SemTypeRef], list[AnnotationSet]]
|
Tuple of (valence_patterns, semtypes, annotation_sets). |
Examples:
>>> converter = FrameNetConverter()
>>> patterns, semtypes, annosets = converter.convert_lu_file("lu/lu10.xml")
>>> print(f"Found {len(patterns)} valence patterns")
Source code in src/glazing/framenet/converter.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | |
convert_lu_index_file(filepath: Path | str) -> list[LexicalUnit]
¶
Convert luIndex.xml to a list of LexicalUnit models.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to luIndex.xml file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[LexicalUnit]
|
List of parsed LexicalUnit models. |
Examples:
>>> converter = FrameNetConverter()
>>> lus = converter.convert_lu_index_file("framenet_v17/luIndex.xml")
>>> print(f"Loaded {len(lus)} lexical units")
'Loaded 13575 lexical units'
Source code in src/glazing/framenet/converter.py
convert_semtypes_file(filepath: Path | str, output_file: Path | str) -> int
¶
Convert semTypes.xml to JSON Lines format.
Parses the semantic type hierarchy and writes each type as a JSON line.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to semTypes.xml file.
TYPE:
|
output_file
|
Output JSON Lines file path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of semantic types converted. |
Examples:
>>> converter = FrameNetConverter()
>>> count = converter.convert_semtypes_file("semTypes.xml", "semtypes.jsonl")
>>> print(f"Converted {count} semantic types")
Source code in src/glazing/framenet/converter.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
Functions¶
convert_frame_file(filepath: Path | str) -> Frame
¶
Convert a single frame XML file to Frame model.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Path to frame XML file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Frame
|
Parsed Frame model. |
Source code in src/glazing/framenet/converter.py
convert_frames_directory(input_dir: Path | str, output_file: Path | str, pattern: str = '*.xml') -> int
¶
Convert all frames in a directory to JSON Lines.
| PARAMETER | DESCRIPTION |
|---|---|
input_dir
|
Directory with frame XML files.
TYPE:
|
output_file
|
Output JSON Lines file.
TYPE:
|
pattern
|
File pattern to match.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of frames converted. |