FrameNet_v17 / FrameNet_1.7.py
liyucheng's picture
Rename FrameNet_1.7 to FrameNet_1.7.py
513f4c1
raw
history blame
23.7 kB
import datasets
import os
import pandas as pd
frame2id = {'_': 0, 'Event_instance': 1, 'Luck': 2, 'Medical_professionals': 3, 'Process_stop': 4, 'Agriculture': 5, 'Sleep': 6, 'Request': 7, 'Come_down_with': 8, 'Manufacturing': 9, 'Ingredients': 10, 'Processing_materials': 11, 'Intoxicants': 12, 'Scope': 13, 'Sociability': 14, 'Prison': 15, 'Trust': 16, 'Intercepting': 17, 'Take_place_of': 18, 'Bungling': 19, 'Leadership': 20, 'Presence': 21, 'People_by_morality': 22, 'Activity_prepare': 23, 'Political_locales': 24, 'Cause_harm': 25, 'Expressing_publicly': 26, 'Communication_noise': 27, 'Origin': 28, 'Opportunity': 29, 'Objective_influence': 30, 'Amassing': 31, 'Margin_of_resolution': 32, 'Cause_to_wake': 33, 'Economy': 34, 'Capacity': 35, 'Becoming': 36, 'Forgiveness': 37, 'Be_in_agreement_on_action': 38, 'Amounting_to': 39, 'Departing': 40, 'Defending': 41, 'Deserving': 42, 'Detaining': 43, 'Communication_manner': 44, 'Medical_specialties': 45, 'Evidence': 46, 'People_along_political_spectrum': 47, 'Relational_quantity': 48, 'Transition_to_a_quality': 49, 'Adopt_selection': 50, 'Reparation': 51, 'Amalgamation': 52, 'Inhibit_movement': 53, 'Electricity': 54, 'Topic': 55, 'Relative_time': 56, 'Sending': 57, 'Activity_pause': 58, 'Military': 59, 'Expectation': 60, 'Extradition': 61, 'Aging': 62, 'Examination': 63, 'Have_associated': 64, 'Ingest_substance': 65, 'Preventing_or_letting': 66, 'Extreme_value': 67, 'Achieving_first': 68, 'Usefulness': 69, 'Education_teaching': 70, 'Becoming_silent': 71, 'Finish_competition': 72, 'Accomplishment': 73, 'Cause_to_make_noise': 74, 'Fall_asleep': 75, 'Food': 76, 'Sign': 77, 'Telling': 78, 'Used_up': 79, 'Undergoing': 80, 'Colonization': 81, 'Obscurity': 82, 'Apply_heat': 83, 'Being_in_captivity': 84, 'Eclipse': 85, 'Killing': 86, 'Judgment_direct_address': 87, 'Bail_decision': 88, 'Manner': 89, 'Predicament': 90, 'Delivery': 91, 'Distributed_position': 92, 'Robbery': 93, 'Motion': 94, 'Turning_out': 95, 'Location_in_time': 96, 'Becoming_dry': 97, 'Cause_to_perceive': 98, 'Expected_location_of_person': 99, 'Process_end': 100, 'Dominate_competitor': 101, 'Change_of_phase': 102, 'Being_in_control': 103, 'Halt': 104, 'Left_to_do': 105, 'Project': 106, 'Cause_impact': 107, 'Individual_history': 108, 'Position_on_a_scale': 109, 'Needing': 110, 'Destroying': 111, 'Possession': 112, 'Connecting_architecture': 113, 'Thriving': 114, 'Gathering_up': 115, 'Piracy': 116, 'Shapes': 117, 'Rescuing': 118, 'Perception_active': 119, 'Stage_of_progress': 120, 'Withdraw_from_participation': 121, 'Accompaniment': 122, 'Improvement_or_decline': 123, 'Punctual_perception': 124, 'Becoming_aware': 125, 'Rewards_and_punishments': 126, 'Using': 127, 'Text': 128, 'Being_in_effect': 129, 'Law': 130, 'Kinship': 131, 'Change_event_duration': 132, 'Popularity': 133, 'Infrastructure': 134, 'Arrest': 135, 'Part_whole': 136, 'Regard': 137, 'Sound_level': 138, 'Delimitation_of_diversity': 139, 'Being_at_risk': 140, 'Change_post-state': 141, 'Practice': 142, 'Endangering': 143, 'Earnings_and_losses': 144, 'Body_parts': 145, 'Cogitation': 146, 'Contrition': 147, 'Relation': 148, 'Taking_time': 149, 'Ineffability': 150, 'Process_start': 151, 'Similarity': 152, 'Means': 153, 'Temporal_subregion': 154, 'Range': 155, 'System_complexity': 156, 'Reveal_secret': 157, 'Daring': 158, 'Part_ordered_segments': 159, 'Likelihood': 160, 'Committing_crime': 161, 'Exemplar': 162, 'Memory': 163, 'Fullness': 164, 'Dominate_situation': 165, 'Duration_relation': 166, 'Making_arrangements': 167, 'Scarcity': 168, 'Deciding': 169, 'Being_in_operation': 170, 'Catching_fire': 171, 'Competition': 172, 'Coming_to_be': 173, 'Boundary': 174, 'Typicality': 175, 'Activity_stop': 176, 'Wealthiness': 177, 'Intentionally_create': 178, 'Serving_in_capacity': 179, 'Subjective_influence': 180, 'Being_wet': 181, 'Buildings': 182, 'Commerce_sell': 183, 'Interior_profile_relation': 184, 'Being_dry': 185, 'Besieging': 186, 'Indigenous_origin': 187, 'Progression': 188, 'State_of_entity': 189, 'Architectural_part': 190, 'Intentional_traversing': 191, 'Being_necessary': 192, 'Change_of_leadership': 193, 'Ammunition': 194, 'Suitability': 195, 'Change_operational_state': 196, 'Abounding_with': 197, 'Information': 198, 'Body_movement': 199, 'Inclination': 200, 'Part_piece': 201, 'Supply': 202, 'Point_of_dispute': 203, 'Ride_vehicle': 204, 'Instance': 205, 'Quitting_a_place': 206, 'Invading': 207, 'Candidness': 208, 'Making_faces': 209, 'Encoding': 210, 'Sent_items': 211, 'Religious_belief': 212, 'Fastener': 213, 'Taking_sides': 214, 'Fairness_evaluation': 215, 'Assessing': 216, 'Scouring': 217, 'Sign_agreement': 218, 'Soaking_up': 219, 'Create_physical_artwork': 220, 'Social_event': 221, 'Hearsay': 222, 'Adjusting': 223, 'Enforcing': 224, 'Tolerating': 225, 'Offshoot': 226, 'Social_interaction_evaluation': 227, 'Run_risk': 228, 'People': 229, 'Create_representation': 230, 'Operational_testing': 231, 'Sounds': 232, 'Biological_area': 233, 'Heralding': 234, 'Labor_product': 235, 'Cause_change_of_position_on_a_scale': 236, 'Judgment': 237, 'Undergo_change': 238, 'Cause_to_make_progress': 239, 'Being_employed': 240, 'Speak_on_topic': 241, 'Bearing_arms': 242, 'Documents': 243, 'Catastrophe': 244, 'Categorization': 245, 'Disembarking': 246, 'Evaluative_comparison': 247, 'Medical_conditions': 248, 'Judicial_body': 249, 'Ranked_expectation': 250, 'Success_or_failure': 251, 'Cause_to_amalgamate': 252, 'Rite': 253, 'Hit_or_miss': 254, 'Social_connection': 255, 'Alliance': 256, 'Measure_linear_extent': 257, 'Ground_up': 258, 'Certainty': 259, 'Transfer': 260, 'Hiring': 261, 'Clothing': 262, 'Cause_motion': 263, 'Being_attached': 264, 'Out_of_existence': 265, 'Reliance': 266, 'Capability': 267, 'Memorization': 268, 'Storing': 269, 'Offenses': 270, 'Misdeed': 271, 'Communication_response': 272, 'First_experience': 273, 'Fear': 274, 'Just_found_out': 275, 'Foreign_or_domestic_country': 276, 'Scrutiny': 277, 'Respond_to_proposal': 278, 'Mass_motion': 279, 'Going_back_on_a_commitment': 280, 'Rate_description': 281, 'Breathing': 282, 'Desiring': 283, 'Using_resource': 284, 'Intentionally_act': 285, 'Cure': 286, 'Having_or_lacking_access': 287, 'Render_nonfunctional': 288, 'Representative': 289, 'Commerce_pay': 290, 'Notification_of_charges': 291, 'Prominence': 292, 'Closure': 293, 'Preference': 294, 'Imprisonment': 295, 'Desirable_event': 296, 'Ratification': 297, 'Getting_vehicle_underway': 298, 'Beyond_compare': 299, 'History': 300, 'Attention': 301, 'Translating': 302, 'Disgraceful_situation': 303, 'Noise_makers': 304, 'Addiction': 305, 'Attending': 306, 'Seeking_to_achieve': 307, 'Measurable_attributes': 308, 'Attaching': 309, 'Gizmo': 310, 'Partiality': 311, 'Adjacency': 312, 'Meet_with': 313, 'Cause_fluidic_motion': 314, 'Institutionalization': 315, 'Motion_noise': 316, 'Make_noise': 317, 'Perception_experience': 318, 'Temperature': 319, 'Criminal_investigation': 320, 'Completeness': 321, 'Waiting': 322, 'Discussion': 323, 'Reassuring': 324, 'Be_in_agreement_on_assessment': 325, 'Vocalizations': 326, 'Undergo_transformation': 327, 'Quantity': 328, 'Quantified_mass': 329, 'Forgoing': 330, 'Obviousness': 331, 'Measure_area': 332, 'Referring_by_name': 333, 'Performing_arts': 334, 'Directional_locative_relation': 335, 'Cutting': 336, 'Physical_artworks': 337, 'Accoutrements': 338, 'Complaining': 339, 'Grinding': 340, 'Being_active': 341, 'Estimating': 342, 'Reason': 343, 'Shoot_projectiles': 344, 'Fleeing': 345, 'Cause_expansion': 346, 'Arraignment': 347, 'Abandonment': 348, 'Statement': 349, 'Verdict': 350, 'Text_creation': 351, 'Placing': 352, 'Biological_urge': 353, 'Beat_opponent': 354, 'Activity_start': 355, 'Filling': 356, 'Stimulus_focus': 357, 'Have_as_requirement': 358, 'Make_acquaintance': 359, 'Putting_out_fire': 360, 'Purpose': 361, 'Mental_stimulus_stimulus_focus': 362, 'Offering': 363, 'Agree_or_refuse_to_act': 364, 'Remembering_experience': 365, 'Giving_in': 366, 'Measure_mass': 367, 'Sidereal_appearance': 368, 'Linguistic_meaning': 369, 'Eventive_affecting': 370, 'Process_completed_state': 371, 'Emotions_by_stimulus': 372, 'Prohibiting_or_licensing': 373, 'Measure_duration': 374, 'Experience_bodily_harm': 375, 'Natural_features': 376, 'Emergency_fire': 377, 'Frequency': 378, 'Response': 379, 'Frugality': 380, 'Non-gradable_proximity': 381, 'Estimated_value': 382, 'Animals': 383, 'Front_for': 384, 'Kidnapping': 385, 'Mental_stimulus_exp_focus': 386, 'Measure_volume': 387, 'Work': 388, 'Adducing': 389, 'Exchange': 390, 'Manipulate_into_doing': 391, 'Giving_birth': 392, 'Locale_by_event': 393, 'Evoking': 394, 'Body_mark': 395, 'Shopping': 396, 'Moving_in_place': 397, 'Version_sequence': 398, 'Communicate_categorization': 399, 'Imposing_obligation': 400, 'Proportion': 401, 'Trying_out': 402, 'Bringing': 403, 'Growing_food': 404, 'Mining': 405, 'Participation': 406, 'Path_shape': 407, 'Distinctiveness': 408, 'Rank': 409, 'Board_vehicle': 410, 'Interrupt_process': 411, 'Color_qualities': 412, 'Performers_and_roles': 413, 'Expansion': 414, 'Compliance': 415, 'Execution': 416, 'Successful_action': 417, 'Rotting': 418, 'Judgment_communication': 419, 'Partitive': 420, 'Excreting': 421, 'Expertise': 422, 'Existence': 423, 'Exporting': 424, 'Give_impression': 425, 'Experiencer_obj': 426, 'Activity_resume': 427, 'Affirm_or_deny': 428, 'Co-association': 429, 'Emphasizing': 430, 'Irregular_combatants': 431, 'Legality': 432, 'Money': 433, 'Guilt_or_innocence': 434, 'People_by_residence': 435, 'Tasting': 436, 'Extreme_point': 437, 'Degree_of_processing': 438, 'Cause_to_start': 439, 'Wearing': 440, 'Diversity': 441, 'Historic_event': 442, 'Public_services': 443, 'Setting_fire': 444, 'Cause_change': 445, 'Actually_occurring_entity': 446, 'Isolated_places': 447, 'Member_of_military': 448, 'Temporary_stay': 449, 'Abusing': 450, 'Dispersal': 451, 'Giving': 452, 'Dimension': 453, 'Path_traveled': 454, 'Direction': 455,
'Stinginess': 456, 'Strictness': 457, 'Behind_the_scenes': 458, 'Being_obligated': 459, 'Make_agreement_on_action': 460, 'Change_posture': 461, 'Attack': 462, 'Fields': 463, 'Billing': 464, 'Medium': 465, 'Activity_finish': 466, 'Research': 467, 'Cause_bodily_experience': 468, 'Change_tool': 469, 'Vehicle': 470, 'Emotion_directed': 471, 'Process': 472, 'Nuclear_process': 473, 'Control': 474, 'Level_of_force_resistance': 475, 'Possibility': 476, 'Arson': 477, 'Avoiding': 478, 'Roadways': 479, 'Creating': 480, 'Claim_ownership': 481, 'Active_substance': 482, 'Convey_importance': 483, 'Supporting': 484, 'Separating': 485, 'Labeling': 486, 'Sentencing': 487, 'Attempt_means': 488, 'Light_movement': 489, 'Businesses': 490, 'Cause_to_continue': 491, 'Verification': 492, 'Forging': 493, 'Fluidic_motion': 494, 'Team': 495, 'Grasp': 496, 'Being_relevant': 497, 'Travel': 498, 'Temporal_collocation': 499, 'State_continue': 500, 'Volubility': 501, 'Cause_change_of_phase': 502, 'Remembering_information': 503, 'Opinion': 504, 'Commerce_buy': 505, 'Part_inner_outer': 506, 'Launch_process': 507, 'Destiny': 508, 'Try_defendant': 509, 'Execute_plan': 510, 'Explaining_the_facts': 511, 'People_by_origin': 512, 'Age': 513, 'Confronting_problem': 514, 'Hostile_encounter': 515, 'Assistance': 516, 'Arranging': 517, 'Mental_property': 518, 'Abundance': 519, 'Breaking_out_captive': 520, 'Manner_of_life': 521, 'Hit_target': 522, 'Traversing': 523, 'Employing': 524, 'Emanating': 525, 'Taking': 526, 'Redirecting': 527, 'People_by_vocation': 528, 'People_by_religion': 529, 'Body_description_holistic': 530, 'Timespan': 531, 'Revenge': 532, 'Medical_intervention': 533, 'Appointing': 534, 'Hospitality': 535, 'Commemorative': 536, 'Terrorism': 537, 'Surrendering_possession': 538, 'Choosing': 539, 'Entering_of_plea': 540, 'Come_together': 541, 'Concessive': 542, 'System': 543, 'Building': 544, 'Awareness_status': 545, 'Type': 546, 'Motion_directional': 547, 'Name_conferral': 548, 'Sequence': 549, 'Artificiality': 550, 'Hunting': 551, 'Degree': 552, 'Transition_to_state': 553, 'Prevent_or_allow_possession': 554, 'Pattern': 555, 'Aiming': 556, 'Quitting': 557, 'Retaining': 558, 'Recording': 559, 'Judgment_of_intensity': 560, 'Craft': 561, 'Cardinal_numbers': 562, 'Membership': 563, 'Simple_name': 564, 'Terms_of_agreement': 565, 'Damaging': 566, 'Required_event': 567, 'Source_of_getting': 568, 'Reading_activity': 569, 'Death': 570, 'Secrecy_status': 571, 'Biological_entity': 572, 'Probability': 573, 'Store': 574, 'Institutions': 575, 'Unattributed_information': 576, 'Arriving': 577, 'Size': 578, 'Impression': 579, 'Becoming_a_member': 580, 'Self_motion': 581, 'Cooking_creation': 582, 'Willingness': 583, 'Cause_to_fragment': 584, 'Collaboration': 585, 'Communication': 586, 'Conduct': 587, 'Locale_by_use': 588, 'Cause_emotion': 589, 'Fame': 590, 'Ambient_temperature': 591, 'Locative_relation': 592, 'Gesture': 593, 'Rest': 594, 'Rape': 595, 'Forming_relationships': 596, 'Cause_to_resume': 597, 'Locale_by_ownership': 598, 'Weather': 599, 'Inspecting': 600, 'Installing': 601, 'Attributed_information': 602, 'Indicating': 603, 'Unemployment_rate': 604, 'First_rank': 605, 'Activity_ongoing': 606, 'Attempt_suasion': 607, 'Being_questionable': 608, 'Trial': 609, 'Importing': 610, 'Be_subset_of': 611, 'Cause_to_end': 612, 'Fire_burning': 613, 'Compatibility': 614, 'Activity_done_state': 615, 'Proliferating_in_number': 616, 'Removing': 617, 'Accuracy': 618, 'Emptying': 619, 'Lively_place': 620, 'Reading_perception': 621, 'Part_orientational': 622, 'Aggregate': 623, 'Chatting': 624, 'Spatial_co-location': 625, 'Locale': 626, 'Awareness': 627, 'Commercial_transaction': 628, 'Sole_instance': 629, 'Familiarity': 630, 'Occupy_rank': 631, 'Process_resume': 632, 'Suasion': 633, 'Color': 634, 'Thwarting': 635, 'Organization': 636, 'Coming_to_believe': 637, 'Theft': 638, 'Reference_text': 639, 'Connectors': 640, 'Hindering': 641, 'Omen': 642, 'Containers': 643, 'Preliminaries': 644, 'Sufficiency': 645, 'Facial_expression': 646, 'Morality_evaluation': 647, 'Being_located': 648, 'Justifying': 649, 'Intentionally_affect': 650, 'Deny_or_grant_permission': 651, 'Visiting': 652, 'Legal_rulings': 653, 'Posture': 654, 'Network': 655, 'People_by_jurisdiction': 656, 'Proper_reference': 657, 'Substance': 658, 'Surviving': 659, 'Smuggling': 660, 'Commitment': 661, 'Weapon': 662, 'Suspicion': 663, 'Subversion': 664, 'Sensation': 665, 'Ceasing_to_be': 666, 'Containing': 667, 'Contacting': 668, 'Conquering': 669, 'Importance': 670, 'Submitting_documents': 671, 'Firing': 672, 'Cause_change_of_strength': 673, 'Correctness': 674, 'Exchange_currency': 675, 'Feeling': 676, 'Temporal_pattern': 677, 'Causation': 678, 'Predicting': 679, 'Protecting': 680, 'Preserving': 681, 'Relational_natural_features': 682, 'Releasing': 683, 'Reasoning': 684, 'Residence': 685, 'Replacing': 686, 'Receiving': 687, 'Reshaping': 688, 'Expensiveness': 689, 'Reporting': 690, 'Subordinates_and_superiors': 691, 'Operate_vehicle': 692, 'Manipulation': 693, 'Rebellion': 694, 'Touring': 695, 'Location_of_light': 696, 'Being_operational': 697, 'Remainder': 698, 'Chemical-sense_description': 699, 'Entity': 700, 'Desirability': 701, 'Commerce_scenario': 702, 'Food_gathering': 703, 'Holding_off_on': 704, 'Within_distance': 705, 'Resolve_problem': 706, 'Questioning': 707, 'Being_named': 708, 'Risky_situation': 709, 'Negation': 710, 'Calendric_unit': 711, 'Alternatives': 712, 'Renting': 713, 'Reliance_on_expectation': 714, 'Increment': 715, 'Simple_naming': 716, 'Clothing_parts': 717, 'Simultaneity': 718, 'Rejuvenation': 719, 'Precipitation': 720, 'Renunciation': 721, 'Prevarication': 722, 'Attempt': 723, 'Law_enforcement_agency': 724, 'Ingestion': 725, 'Level_of_force_exertion': 726, 'Inclusion': 727, 'Spatial_contact': 728, 'Custom': 729, 'Hiding_objects': 730, 'People_by_age': 731, 'Contingency': 732, 'Coincidence': 733, 'Impact': 734, 'Quarreling': 735, 'Aesthetics': 736, 'Cognitive_connection': 737, 'Getting': 738, 'Being_incarcerated': 739, 'Coming_up_with': 740, 'Change_event_time': 741, 'Setting_out': 742, 'Openness': 743, 'Assemble': 744, 'Reading_aloud': 745, 'Difficulty': 746, 'Change_position_on_a_scale': 747, 'Planned_trajectory': 748, 'Becoming_separated': 749, 'Cause_to_move_in_place': 750, 'Continued_state_of_affairs': 751, 'Experiencer_focus': 752, 'Seeking': 753, 'Emotions_of_mental_activity': 754, 'Immobilization': 755, 'Firefighting': 756, 'Reforming_a_system': 757, 'Identicality': 758, 'Locating': 759, 'Event': 760, 'Attitude_description': 761, 'Personal_relationship': 762, 'Goal': 763, 'Artifact': 764, 'Emotion_active': 765, 'Recovery': 766, 'Duration_description': 767, 'Speed_description': 768, 'Relational_political_locales': 769, 'Win_prize': 770, 'Rate_quantification': 771, 'Summarizing': 772, 'Cause_to_experience': 773, 'Activity_ready_state': 774, 'Sharpness': 775, 'Escaping': 776, 'Waking_up': 777, 'Toxic_substance': 778, 'Dead_or_alive': 779, 'Differentiation': 780, 'Operating_a_system': 781, 'Change_direction': 782, 'Proportional_quantity': 783, 'Domain': 784, 'Time_vector': 785, 'Ordinal_numbers': 786, 'Trendiness': 787, 'Idiosyncrasy': 788, 'Building_subparts': 789, 'Being_born': 790, 'Being_in_category': 791, 'Process_continue': 792, 'Carry_goods': 793, 'Duplication': 794, 'Make_cognitive_connection': 795, 'Cotheme': 796}
class FN17Config(datasets.BuilderConfig):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.train_file = 'fn1.7.fulltext.train.syntaxnet.conll'
self.dev_file = 'fn1.7.dev.syntaxnet.conll'
self.test_file = 'fn1.7.test.syntaxnet.conll'
class FN17(datasets.GeneratorBasedBuilder):
BUILDER_CONFIG_CLASS = FN17Config
def _info(self):
if self.config.name == 'default':
return datasets.DatasetInfo(
description = 'FrameNet v1.7',
features = datasets.Features(
{
'id':datasets.Value('int32'),
'sent_id':datasets.Value('int32'),
'tokens':datasets.Sequence(datasets.Value('string')),
'frame_tags':datasets.Sequence(datasets.features.ClassLabel(num_classes=len(frame2id), names=list(frame2id.keys()))),
'coarse_pos':datasets.Sequence(datasets.Value('string')),
'fine_pos':datasets.Sequence(datasets.Value('string')),
'lemma':datasets.Sequence(datasets.Value('string')),
'LUs':datasets.Sequence(datasets.Value('string')),
'FEs':datasets.Sequence(datasets.Value('string')),
}
)
)
elif self.config.name == 'frame_label':
return datasets.DatasetInfo(
description = 'Frame Label annotation, Used to train the frame label classifier. Please refer to the paper of OpenSesame.',
features = datasets.Features(
{
'id':datasets.Value('int32'),
'tokens':datasets.Sequence(datasets.Value('string')),
'frame_tags':datasets.Sequence(datasets.features.ClassLabel(num_classes=len(frame2id), names=list(frame2id.keys())))
}
)
)
def _split_generators(self, dl_manager):
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={'filepath': dl_manager.download(os.path.join('fn1.7', self.config.train_file))}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={'filepath': dl_manager.download(os.path.join('fn1.7', self.config.dev_file))}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={'filepath': dl_manager.download(os.path.join('fn1.7', self.config.test_file))}),
]
def _generate_examples(self, filepath):
if self.config.name == 'default':
with open(filepath, encoding='utf-8') as f:
id = 0
sent_id = 0
tokens = []
frame_tags = []
coarse_pos = []
fine_pos = []
lemma = []
LUs = []
FEs = []
for line in f:
if line == '' or line == '\n':
if tokens:
yield id, {
'id': id,
'sent_id': sent_id,
'tokens': tokens,
'frame_tags': frame_tags,
'coarse_pos': coarse_pos,
'fine_pos': fine_pos,
'lemma': lemma,
'LUs': LUs,
'FEs': FEs
}
id+=1
tokens=[]
frame_tags = []
coarse_pos = []
fine_pos = []
lemma = []
LUs = []
FEs = []
else:
splits = line.split('\t')
tokens.append(splits[1][2:-1])
lemma.append(splits[3])
coarse_pos.append(splits[4])
fine_pos.append(splits[5])
LUs.append(splits[-3])
frame_tags.append(splits[-2])
FEs.append(splits[-1])
sent_id = int(splits[6])
if len(tokens):
yield id, {
'id': id,
'sent_id': sent_id,
'tokens': tokens,
'frame_tags': frame_tags,
'coarse_pos': coarse_pos,
'fine_pos': fine_pos,
'lemma': lemma,
'LUs': LUs,
'FEs': FEs
}
elif self.config.name == 'frame_label':
sents = []
with open(filepath, encoding='utf-8') as f:
id = 0
sent_id = 0
tokens = []
frame_tags = []
for line in f:
if line == '' or line == '\n':
if tokens:
sents.append({'tokens':tokens, 'frame_tags':frame_tags, 'sent_id':sent_id, 'id':id})
id+=1
tokens=[]
frame_tags = []
else:
splits = line.split('\t')
tokens.append(splits[1][2:-1])
frame_tags.append(splits[-2])
sent_id = int(splits[6])
if len(tokens):
sents.append({'tokens':tokens, 'frame_tags':frame_tags, 'sent_id':sent_id, 'id':id})
df = pd.DataFrame(sents)
for index, (sent_id, group) in enumerate(df.groupby('sent_id')):
tokens = group.iloc[0]['tokens']
frame_tags = ['_'] * len(tokens)
for i, row in group.iterrows():
for tag_i, tag in enumerate(row['frame_tags']):
if tag != '_':
frame_tags[tag_i] = tag
yield index, {
'id': sent_id,
'tokens': tokens,
'frame_tags': frame_tags
}