<commit_before># -*- encoding: utf-8 -*-

import pyparsing as pp

from data.accessor import CWRConfiguration, CWRTables
from cwr.grammar import field, field_special, record, society, field_table
from cwr.interested_party import Publisher, PublisherRecord


"""
CWR Publisher Record grammar.

This is for the following records:
- Publisher Controlled By Submitter Record (SPU)
- Other Publisher Record (OPU)
"""

__author__ = '<NAME>'
__license__ = 'MIT'
__version__ = '0.0.0'
__status__ = 'Development'

# Acquires data sources
_tables = CWRTables()
_config = CWRConfiguration()

"""
Publisher fields.
"""

# Publisher Sequence #
sequence_n = field.numeric(_config.field_size('publisher', 'sequence_n'), compulsory=True)
sequence_n = sequence_n.setName('Publisher Sequence #').setResultsName('sequence_n')

# Publisher name
name = field.alphanum(_config.field_size('publisher', 'name'))
name = name.setName('Publisher name').setResultsName('name')

# Publisher Unknown Indicator
unknown = field.flag()
unknown = unknown.setName('Publisher Unknown Indicator').setResultsName('publisher_unknown')

# Tax ID #
tax_id = field.alphanum(_config.field_size('publisher', 'tax_id'))
tax_id = tax_id.setName('Tax ID #').setResultsName('tax_id')

# Submitter Agreement Number
agreement_id = field.alphanum(_config.field_size('publisher', 'submitter_agreement_id'))
agreement_id = agreement_id.setName('Submitter Agreement Number').setResultsName('submitter_agreement_id')

# PR Affiliation Society #
pr_society = field.alphanum(_config.field_size('publisher', 'pr_society'))
pr_society = pr_society.setName('PR Affiliation Society #').setResultsName('pr_society')

# First Recording Refusal Indicator
first_refusal = field.flag()
first_refusal = first_refusal.setName('First Recording Refusal Indicator').setResultsName('first_record_refusal')

# Filler
filler = pp.Literal(' ')
filler.leaveWhitespace()
filler.suppress()

# Publisher IPI Base Number
ipi_base = field_special.ipi_base_number()

# International Standard Agreement Code
international_code = field.alphanum(_config.field_size('publisher', 'international_code'))
international_code = international_code.setName('International Standard Agreement Code').setResultsName(
    'isac')

# Society-assigned Agreement Number
society_id = field.alphanum(_config.field_size('publisher', 'society_agreement_id'))
society_id = society_id.setName('Society-assigned Agreement Number').setResultsName('society_agreement_id')

"""
Publisher patterns.
"""

publisher = field_special.lineStart + record.record_prefix(_config.record_type('publisher')) + sequence_n + \
            field_special.ip_id() + name + unknown + \
            field_table.publisher_type() + tax_id + field_special.ipi_name_number() + agreement_id + \
            society.pr_affiliation() + society.pr_share + \
            society.mr_affiliation() + society.mr_share + \
            society.sr_affiliation() + society.sr_share + \
            field_table.special_agreement() + first_refusal + filler + ipi_base + international_code + \
            society_id + field_table.agreement_type() + field_table.usa_license() + field_special.lineEnd

"""
Parsing actions for the patterns.
"""

publisher.setParseAction(lambda p: _to_publisherrecord(p))

"""
Parsing methods.<commit_msg>Corrected grammar error for old versions of PyParsing<commit_after># -*- encoding: utf-8 -*-

import pyparsing as pp

from data.accessor import CWRConfiguration, CWRTables
from cwr.grammar import field, field_special, record, society, field_table
from cwr.interested_party import Publisher, PublisherRecord


"""
CWR Publisher Record grammar.

This is for the following records:
- Publisher Controlled By Submitter Record (SPU)
- Other Publisher Record (OPU)
"""

__author__ = '<NAME>'
__license__ = 'MIT'
__version__ = '0.0.0'
__status__ = 'Development'

# Acquires data sources
_tables = CWRTables()
_config = CWRConfiguration()

"""
Publisher fields.
"""

# Publisher Sequence #
sequence_n = field.numeric(_config.field_size('publisher', 'sequence_n'), compulsory=True)
sequence_n = sequence_n.setName('Publisher Sequence #').setResultsName('sequence_n')

# Publisher name
name = field.alphanum(_config.field_size('publisher', 'name'))
name = name.setName('Publisher name').setResultsName('name')

# Publisher Unknown Indicator
unknown = field.flag()
unknown = unknown.setName('Publisher Unknown Indicator').setResultsName('publisher_unknown')

# Tax ID #
tax_id = field.alphanum(_config.field_size('publisher', 'tax_id'))
tax_id = tax_id.setName('Tax ID #').setResultsName('tax_id')

# Submitter Agreement Number
agreement_id = field.alphanum(_config.field_size('publisher', 'submitter_agreement_id'))
agreement_id = agreement_id.setName('Submitter Agreement Number').setResultsName('submitter_agreement_id')

# PR Affiliation Society #
pr_society = field.alphanum(_config.field_size('publisher', 'pr_society'))
pr_society = pr_society.setName('PR Affiliation Society #').setResultsName('pr_society')

# First Recording Refusal Indicator
first_refusal = field.flag()
first_refusal = first_refusal.setName('First Recording Refusal Indicator').setResultsName('first_record_refusal')

# Filler
filler = pp.Literal(' ')
filler.leaveWhitespace()
filler.suppress()

# Publisher IPI Base Number
ipi_base = field_special.ipi_base_number()

# International Standard Agreement Code
international_code = field.alphanum(_config.field_size('publisher', 'international_code'))
international_code = international_code.setName('International Standard Agreement Code').setResultsName(
    'isac')

# Society-assigned Agreement Number
society_id = field.alphanum(_config.field_size('publisher', 'society_agreement_id'))
society_id = society_id.setName('Society-assigned Agreement Number').setResultsName('society_agreement_id')

"""
Publisher patterns.
"""

publisher = field_special.lineStart + record.record_prefix(_config.record_type('publisher')) + sequence_n + \
            field_special.ip_id() + name + unknown + \
            field_table.publisher_type() + tax_id + field_special.ipi_name_number() + agreement_id + \
            society.pr_affiliation + society.pr_share + \
            society.mr_affiliation + society.mr_share + \
            society.sr_affiliation + society.sr_share + \
            field_table.special_agreement() + first_refusal + filler + ipi_base + international_code + \
            society_id + field_table.agreement_type() + field_table.usa_license() + field_special.lineEnd

"""
Parsing actions for the patterns.
"""

publisher.setParseAction(lambda p: _to_publisherrecord(p))

"""
Validation actions for the patterns.
"""


"""
Parsing methods.
{'fraction_non_alphanumeric': 0.11705484598046581, 'fraction_numerical': 0.0012021036814425245, 'mean_word_length': 5.791836734693877, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5361421', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2010, 'n_words': 415}