-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/parlamint turkey #1730
Draft
Meesch
wants to merge
11
commits into
develop
Choose a base branch
from
feature/parlamint-turkey
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Feature/parlamint turkey #1730
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4f37a79
improve docs (typos and broken link)
Meesch 76776ca
update launch json to include loadcorpora
Meesch 81463b2
preliminary corpus definition turkiye
Meesch ec5c678
add organisational metadata to parlamint turkiye
Meesch ffced2b
add more speaker metadata to parlamint turkiye
Meesch e3fe322
add role info for parlamint turkiye
Meesch 83554ea
add speaker_constituency to parlamint-turkiye
Meesch 0e931e4
cleanup
Meesch 4169706
add description page for parlamint-turkiye
Meesch 1c7844d
cleanup
Meesch 8c6afb7
additional documentation
Meesch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 deletions
24
backend/corpora/parliament/clarin_parlamint/description/parlamint_turkiye.md
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,24 @@ | ||
# Corpus of parliamentary debates ParlaMint-TR | ||
|
||
- Country: TR (Turkey) | ||
- Language tr (Turkish) | ||
- Version: 4.1 | ||
- Handle: [http://hdl.handle.net/11356/1912](http://hdl.handle.net/11356/1912) | ||
|
||
|
||
## Documentation | ||
|
||
### Parlamint Project | ||
ParlaMint, a CLARIN flagship project, resulted in the creation of comparable corpora of parliamentary debates of 29 European countries and autonomous regions, covering at least the period from 2015 to 2022, and containing over 1 billion words. The corpora are uniformly encoded, contain rich metadata about their 24 thousand speakers, and are linguistically annotated up to the level of Universal Dependencies syntax and named entities. | ||
|
||
### Characteristics of the national parliament | ||
|
||
The current parliamentary system in Turkey is a unicameral system (there have been periods of bicameral systems in the past). The political system is a multi-party system. There are no official “political groups”, however, since 2018 parties make alliances during elections, which may affect their relations in the parliament as well. The current version of the corpus contains transcripts of debates in the last four terms (from 24 to 27) of the Grand National Assembly of Turkey (Turkish: Türkiye Büyük Millet Meclisi), which is approximately 50 million words recorded in 1341 sessions from June 2011 to December 2022. | ||
|
||
### Data source and acquisition | ||
|
||
The data is scraped from the official web page of the parliament (https://www.tbmm.gov.tr/). The transcripts for this period are published as HTML documents. The data is downloaded using GNU wget, and extracted from the HTML files using Beautiful Soup, and lxml libraries (Python). Except for the default processing built into these libraries (for encoding correction, HTML cleanup), no other preprocessing was applied. | ||
|
||
### Corpus-specific metadata | ||
|
||
Current version of the corpus contains the sex, the date/place of birth, and when available Wikipedia, Wikidata and Twitter linksfor regular speakers. The corpus also encodes the constituencies of the parliament members. Changes to party affiliations are documented during the time period of the corpus. Otherwise, the start of party affiliation is left unspecified. | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
243 changes: 243 additions & 0 deletions
243
backend/corpora/parliament/clarin_parlamint/parlamint_turkiye.py
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,243 @@ | ||
import logging | ||
from datetime import datetime | ||
from glob import glob | ||
from os.path import join | ||
from bs4 import BeautifulSoup | ||
import re | ||
|
||
from django.conf import settings | ||
|
||
from addcorpus.python_corpora.corpus import XMLCorpusDefinition, FieldDefinition | ||
from addcorpus.python_corpora.extract import XML, Constant, Combined, Order, Metadata, Pass | ||
from addcorpus.es_mappings import keyword_mapping | ||
from corpora.utils.constants import document_context | ||
from corpora.parliament.parliament import Parliament | ||
from corpora.parliament.utils.parlamint_v4 import extract_all_org_data, extract_people_data, person_attribute_extractor, current_party_id_extractor, organisation_attribute_extractor, POLITICAL_ORIENTATIONS, node_is_current | ||
import corpora.parliament.utils.field_defaults as field_defaults | ||
|
||
|
||
from ianalyzer_readers.xml_tag import Tag | ||
|
||
logger = logging.getLogger('indexing') | ||
|
||
|
||
def get_persons_metadata(directory): | ||
with open(join(directory, 'ParlaMint-TR-listPerson.xml'), 'rb') as f: | ||
soup = BeautifulSoup(f.read(), 'xml') | ||
return extract_people_data(soup) | ||
|
||
def get_orgs_metadata(directory): | ||
with open(join(directory, 'ParlaMint-TR-listOrg.xml'), 'rb') as f: | ||
soup = BeautifulSoup(f.read(), 'xml') | ||
return extract_all_org_data(soup) | ||
|
||
def transform_political_orientation(full_string): | ||
if full_string and '#orientation.' in full_string: | ||
return POLITICAL_ORIENTATIONS[full_string.split('.')[1]] | ||
else: | ||
return None | ||
|
||
def transform_parliamentary_role(data): | ||
org_nodes, date = data | ||
for node in org_nodes: | ||
if node['ref'] == '#TBMM' and node['role'] == 'member' and node_is_current(node, date): | ||
return 'MP' | ||
|
||
def transform_ministerial_role(data): | ||
org_nodes, date = data | ||
for node in org_nodes: | ||
if '#mstr.' in node['ref'] and node['role'] == 'head' and node_is_current(node, date): | ||
for child_node in node.children: | ||
if child_node.name == 'roleName' and child_node.get('xml:lang') == 'en': | ||
return child_node.text.strip() | ||
|
||
def transform_speaker_constituency(data): | ||
org_nodes, date = data | ||
for node in org_nodes: | ||
if node['ref'] == '#TBMM' and node['role'] == 'member' and node_is_current(node, date): | ||
if "#constituency-TR." in node['ana']: | ||
return node['ana'].split('#constituency-TR.')[1] if node['ana'].split('#constituency-TR.')[1] else None | ||
else: | ||
return 'Constituency unknown' | ||
|
||
class ParlamintTurkiye(Parliament, XMLCorpusDefinition): | ||
''' | ||
Corpus definition for indexing Turkish parliamentary data from the ParlaMint dataset. | ||
''' | ||
|
||
title = "ParlaMint Türkiye" | ||
description = "Speeches and debates from Türkiye's parliament." | ||
min_date = datetime(year=2011, month=6, day=1) | ||
max_date = datetime(year=2022, month=12, day=31) | ||
data_directory = settings.PARLAMINT_TURKIYE_DATA | ||
es_index = getattr(settings, 'PARLAMINT_TURKIYE_ES_INDEX', 'parlamint-turkiye') | ||
image = 'turkiye.jpg' | ||
description_page = 'parlamint_turkiye.md' | ||
|
||
tag_toplevel = Tag('TEI') | ||
tag_entry = Tag('u') | ||
languages = ['tr'] | ||
|
||
category = 'parliament' | ||
document_context = document_context() | ||
|
||
def sources(self, start, end): | ||
# First collect metadata that is applicable to the whole dataset, like people and parties | ||
persons_metadata = get_persons_metadata(self.data_directory) | ||
orgs_metadata = get_orgs_metadata(self.data_directory) | ||
metadata = { | ||
'persons': persons_metadata, | ||
'organisations': orgs_metadata, | ||
} | ||
|
||
## Then collect metadata that is applicable to the current file and find the paths to each xml file | ||
for year in range(start.year, end.year): | ||
for xml_file in glob('{}/{}/*.xml'.format(self.data_directory, year)): | ||
metadata['date'] = re.search(r"\d{4}-\d{2}-\d{2}", xml_file).group() | ||
yield xml_file, metadata | ||
|
||
country = field_defaults.country() | ||
country.extractor = Constant( | ||
value='Türkiye' | ||
) | ||
|
||
date = field_defaults.date() | ||
date.extractor = XML( | ||
Tag('teiHeader'), | ||
Tag('fileDesc'), | ||
Tag('sourceDesc'), | ||
Tag('bibl'), | ||
Tag('date'), | ||
toplevel=True | ||
) | ||
|
||
debate_id = field_defaults.debate_id() | ||
debate_id.extractor = XML( | ||
attribute='xml:id', | ||
toplevel=True, | ||
) | ||
|
||
speech = field_defaults.speech(language='tr') | ||
speech.extractor = XML( | ||
Tag('seg'), | ||
multiple=True, | ||
flatten=True, | ||
transform='\n'.join) | ||
|
||
speech_id = field_defaults.speech_id() | ||
speech_id.extractor = XML( | ||
attribute='xml:id' | ||
) | ||
|
||
sequence = field_defaults.sequence() | ||
sequence.extractor = Order(transform=lambda value: value + 1) | ||
|
||
speaker = field_defaults.speaker() | ||
speaker.extractor = person_attribute_extractor('name') | ||
|
||
speaker_id = field_defaults.speaker_id() | ||
speaker_id.extractor = person_attribute_extractor('id') | ||
|
||
speaker_gender = field_defaults.speaker_gender() | ||
speaker_gender.extractor = person_attribute_extractor('gender') | ||
|
||
speaker_birth_year = field_defaults.speaker_birth_year() | ||
speaker_birth_year.extractor = person_attribute_extractor('birth_year') | ||
|
||
speaker_birthplace = field_defaults.speaker_birthplace() | ||
speaker_birthplace.extractor = person_attribute_extractor('birthplace') | ||
|
||
speaker_wikimedia = FieldDefinition( | ||
name = 'speaker_wikimedia', | ||
display_name= 'Speaker Wikipedia', | ||
display_type='url', | ||
description='URL to Wikimedia page of the speaker', | ||
es_mapping=keyword_mapping(), | ||
searchable=False, | ||
) | ||
|
||
speaker_twitter = FieldDefinition( | ||
name = 'speaker_twitter', | ||
display_name= 'Speaker Twitter', | ||
display_type='url', | ||
description='URL to Twitter page of the speaker', | ||
es_mapping=keyword_mapping(), | ||
searchable=False, | ||
) | ||
|
||
parliamentary_role = field_defaults.parliamentary_role() | ||
parliamentary_role.extractor = Combined( | ||
person_attribute_extractor('org_nodes'), | ||
Metadata('date'), | ||
transform=transform_parliamentary_role | ||
) | ||
ministerial_role = field_defaults.ministerial_role() | ||
ministerial_role.extractor = Combined( | ||
person_attribute_extractor('org_nodes'), | ||
Metadata('date'), | ||
transform=transform_ministerial_role | ||
) | ||
|
||
current_party_id = field_defaults.party_id() | ||
current_party_id.extractor = current_party_id_extractor() | ||
|
||
current_party = field_defaults.party() | ||
current_party.extractor = organisation_attribute_extractor('name') | ||
|
||
current_party_full = field_defaults.party_full() | ||
current_party_full.extractor = organisation_attribute_extractor('full_name') | ||
|
||
current_party_wiki = FieldDefinition( | ||
name='party_wiki_url', | ||
display_name='Wikimedia URL', | ||
display_type='url', | ||
description='URL to Wikimedia page of the party', | ||
es_mapping=keyword_mapping(), | ||
searchable=False, | ||
) | ||
current_party_wiki.extractor = organisation_attribute_extractor('wikimedia') | ||
|
||
current_party_political_orientation = FieldDefinition( | ||
name='political_orientation', | ||
display_name='Political Orientation', | ||
description="Political leaning according to the ParlaMint team", | ||
es_mapping=keyword_mapping(), | ||
searchable=False | ||
) | ||
current_party_political_orientation.extractor = Pass( | ||
organisation_attribute_extractor('political_orientation'), | ||
transform=transform_political_orientation | ||
) | ||
|
||
speaker_constituency = field_defaults.speaker_constituency() | ||
speaker_constituency.extractor = Combined( | ||
person_attribute_extractor('org_nodes'), | ||
Metadata('date'), | ||
transform=transform_speaker_constituency | ||
) | ||
|
||
def __init__(self): | ||
self.fields = [ | ||
self.debate_id, | ||
self.country, | ||
self.date, | ||
self.speech, | ||
self.speech_id, | ||
self.sequence, | ||
self.speaker, | ||
self.speaker_id, | ||
self.speaker_gender, | ||
self.speaker_birth_year, | ||
self.speaker_birthplace, | ||
self.speaker_wikimedia, | ||
self.speaker_twitter, | ||
self.parliamentary_role, | ||
self.ministerial_role, | ||
self.current_party_id, | ||
self.current_party, | ||
self.current_party_full, | ||
self.current_party_wiki, | ||
self.current_party_political_orientation, | ||
self.speaker_constituency | ||
] | ||
|
1 change: 1 addition & 0 deletions
1
backend/corpora/parliament/clarin_parlamint/wm/documentation.md
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 @@ | ||
ParlaMint Turkiye does not currently include a word model. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"gender" is more appropriate than "sex" in this context (and also what the field is called in the corpus).