#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import re
from corpus_file import CorpusFileRep

duc_categories = {
  "-5925874473255881144": "AP830325-0143",
  "5368594332167718280": "AP880217-0175",
  "1018108595908238830": "AP880318-0051",
  "179115071534821147": "AP880330-0119",
  "8743917323541409012": "AP880331-0140",
  "-7873281042595098479": "AP880409-0015",
  "7614716194570953839": "AP880419-0131",
  "-4319180346466002361": "AP880510-0178",
  "-8327311175661756520": "AP880517-0226",
  "3053453633232254075": "AP880520-0264",
  "3392943339675550183": "AP880601-0040",
  "4890402069205212901": "AP880613-0161",
  "7120641145715572932": "AP880623-0135",
  "-1287189106898367542": "AP880629-0159",
  "1294972064692363318": "AP880630-0295",
  "8318318536830900332": "AP880705-0006",
  "4377916406713472646": "AP880705-0018",
  "6588069613653376521": "AP880705-0109",
  "-1677297379453309779": "AP880714-0142",
  "5960145932306921890": "AP880801-0195",
  "-7278139295894486362": "AP880811-0299",
  "4096051723272656273": "AP880816-0234",
  "-5522285858502763297": "AP880901-0052",
  "-7701375141184732748": "AP880902-0062",
  "-7565490093981924906": "AP880903-0092",
  "-4436288678446144078": "AP880913-0129",
  "-3789036983133940469": "AP880913-0204",
  "-5177052447570322420": "AP880914-0027",
  "4753374323785811070": "AP880914-0079",
  "4390627948158999772": "AP880926-0203",
  "161498837883155808": "AP880927-0089",
  "-4623351322187511549": "AP880927-0117",
  "-3746498716906633255": "AP880928-0054",
  "-1006289734220142551": "AP880928-0146",
  "-4775807130505540093": "AP881009-0072",
  "-8481555973533035879": "AP881017-0235",
  "-4802156101881815658": "AP881018-0136",
  "-5923083805862647847": "AP881126-0007",
  "4049711919994840366": "AP881206-0114",
  "-5456789442093687876": "AP881210-0115",
  "-510630337533885112": "AP881211-0027",
  "-232623250272642968": "AP881216-0017",
  "8779980839163360284": "AP881222-0089",
  "8364707634004782030": "AP881222-0119",
  "7980352106822051875": "AP881222-0126",
  "-4043062078306582100": "AP881227-0185",
  "-5461781195243187872": "AP890111-0217",
  "-7492261933263007746": "AP890111-0227",
  "-7864786949515388594": "AP890117-0132",
  "-3961097149869898853": "AP890131-0280",
  "-889066887251747431": "AP890227-0016",
  "-9020384551485418566": "AP890228-0019",
  "-2774101368548615987": "AP890302-0063",
  "-3640525785424130117": "AP890307-0150",
  "-3706638094631061735": "AP890313-0198",
  "805333141729962707": "AP890314-0237",
  "-1899246866483295454": "AP890316-0018",
  "-2561839084859597584": "AP890322-0010",
  "-788200979218217708": "AP890325-0029",
  "-1015802351260016511": "AP890326-0081",
  "-755576471206145400": "AP890403-0123",
  "7351349625618516258": "AP890404-0260",
  "-8218562375744868387": "AP890501-0176",
  "-3839495500935111582": "AP890502-0205",
  "8843621417503074076": "AP890511-0126",
  "-2448385528918824448": "AP890529-0030",
  "1390629522996769903": "AP890704-0043",
  "538212715197552386": "AP890708-0135",
  "7742132577775820321": "AP890714-0129",
  "-7119721784104619879": "AP890719-0225",
  "924280742600709687": "AP890722-0081",
  "-3667530678604047221": "AP890801-0025",
  "5897506234732250661": "AP890802-0064",
  "-2722552483115854631": "AP890803-0008",
  "8618246028949512884": "AP890805-0126",
  "-8306847851898091538": "AP890907-0221",
  "795116283033967933": "AP890922-0167",
  "1018843269418362740": "AP890930-0100",
  "5102039580043336747": "AP891006-0029",
  "-8008661321521407910": "AP891017-0204",
  "1136146915378453095": "AP891028-0022",
  "2696071589653901001": "AP891116-0115",
  "6309163201504054052": "AP891116-0191",
  "8431552159373351872": "AP891201-0100",
  "7781329781955884079": "AP891210-0079",
  "-235385112841275703": "AP891213-0004",
  "6837680343355348005": "AP900215-0031",
  "-6200590367113944703": "AP900217-0078",
  "-3894322973727855365": "AP900306-0105",
  "7423887442818993954": "AP900313-0191",
  "4367952743821671109": "AP900316-0028",
  "-443575843946916623": "AP900322-0192",
  "-7652265616216242630": "AP900322-0200",
  "-4182631282178195606": "AP900323-0036",
  "7358986326592314704": "AP900416-0188",
  "-7062736372284010549": "AP900419-0121",
  "-5424073830633883612": "AP900424-0035",
  "-8838509403849570899": "AP900426-0054",
  "-5467799555160909770": "AP900428-0005",
  "8917483857122653320": "AP900428-0108",
  "1301572831176350931": "AP900511-0159",
  "6270046812211756500": "AP900512-0038",
  "6422328637733318708": "AP900521-0063",
  "1662114228148022659": "AP900529-0005",
  "1291135336105349508": "AP900601-0040",
  "-8693840185950765578": "AP900607-0039",
  "-7118117473757315055": "AP900619-0006",
  "-1128119466066514629": "AP900625-0160",
  "6218000060778858354": "AP900629-0260",
  "-8597374141081928996": "AP900703-0040",
  "-1770440100354076118": "AP900721-0110",
  "354249098012593495": "AP900829-0120",
  "-201440535605132647": "AP900910-0020",
  "-4578216358376330382": "AP901010-0036",
  "2504104505693945833": "AP901012-0032",
  "4489819375886836845": "AP901013-0046",
  "-6350978663439986987": "AP901029-0035",
  "6775902133537173584": "AP901030-0216",
  "-736819343660610674": "AP901031-0024",
  "4919562134034278256": "AP901130-0060",
  "6426005454750360536": "AP901203-0166",
  "602535610344778498": "AP901231-0012",
  "-4500247297096645912": "FBIS3-11919",
  "-1076955567961878152": "FBIS3-22942",
  "7138180450462003642": "FBIS3-23360",
  "-4827028725171275889": "FBIS3-30788",
  "-1086323070660667867": "FBIS3-41",
  "-8241706365469245881": "FBIS3-51875",
  "-1334654087303673352": "FBIS-41815",
  "-477232281217648240": "FBIS4-27602",
  "-6082640324918208066": "FBIS4-4674",
  "2599166092063374034": "FBIS4-56863",
  "3184643752696933888": "FBIS-45908",
  "4653014101464872031": "FBIS4-67721",
  "-6875076230558048359": "FT911-2650",
  "3029341606818813912": "FT911-3463",
  "-4488335786240173143": "FT911-5176",
  "-3111423008767208991": "FT921-305",
  "-7642958005262945071": "FT921-9310",
  "-479227844312796007": "FT922-10200",
  "-3727307128696627793": "FT922-3171",
  "-624468343716555670": "FT922-6646",
  "4573476153508086200": "FT922-8860",
  "-2778124070867964210": "FT923-5089",
  "-6624582381785618981": "FT923-5267",
  "3478485947164663576": "FT923-5797",
  "-5922422083621662564": "FT923-5835",
  "3221099905007727268": "FT923-5859",
  "-8092064728673615582": "FT923-6038",
  "2427164841472490137": "FT923-6110",
  "-5608397606591579508": "FT923-6455",
  "4137294712220960032": "FT923-7126",
  "746753529127670736": "FT931-11394",
  "8553990384735112294": "FT931-341",
  "5730086109303644068": "FT931-3883",
  "1130028793167251552": "FT932-12322",
  "306716882914207751": "FT932-5855",
  "-222160633882260133": "FT933-10881",
  "-2817971287655174940": "FT933-2760",
  "-8385296966037271682": "FT933-5709",
  "1920422074336616563": "FT933-6011",
  "-8559982077359676991": "FT933-8272",
  "6374554055846104836": "FT933-8941",
  "-6672288394846064616": "FT934-10911",
  "-7236584852132058054": "FT934-11014",
  "-8056712581403542595": "FT934-12800",
  "-4366191372483335117": "FT934-13350",
  "6350499093377052885": "FT934-5781",
  "6234128490940663827": "FT934-8628",
  "8826641583351550246": "FT934-8748",
  "8352627676363971321": "FT934-9116",
  "-2446382603549366789": "FT941-1547",
  "1423209926504344923": "FT941-1750",
  "4807670531382591156": "FT941-4219",
  "5778992152239253476": "FT941-575",
  "-2821740560288240590": "FT942-11114",
  "1539335161043025579": "FT943-12341",
  "-7728056309243992217": "FT943-4951",
  "-4477516946536461321": "FT943-5628",
  "-8472605798103786918": "FT944-18184",
  "3025211733759996917": "LA010890-0031",
  "-4039954575647263759": "LA011889-0067",
  "-6687078221233917851": "LA012090-0090",
  "8565937381462257371": "LA012590-0174",
  "-8312166690057159267": "LA021090-0005",
  "-8231477547548533079": "LA021689-0227",
  "6904014161289422991": "LA030489-0068",
  "-8723194825839829790": "LA030789-0047",
  "-2585263637746870593": "LA030889-0163",
  "-1939935127348250431": "LA032589-0044",
  "-442016102360114200": "LA032789-0038",
  "-4552777579948679218": "LA040689-0056",
  "6781880607339481532": "LA040789-0051",
  "2959783396145519233": "LA041889-0039",
  "-2509099603055347585": "LA042190-0060",
  "4865038918256350584": "LA042290-0104",
  "-4459253854502021749": "LA042490-0142",
  "-9110442711326659330": "LA042790-0205",
  "-610365392330567028": "LA043089-0197",
  "-3440764003853108418": "LA050889-0075",
  "-8878548856691380480": "LA051190-0185",
  "-5531018829072297160": "LA051590-0065",
  "8791094209060487499": "LA052289-0050",
  "4634146993804726964": "LA060490-0083",
  "-2319316358207780286": "LA061589-0143",
  "319662068220127766": "LA070189-0080",
  "-8786180791817085454": "LA070190-0073",
  "8935841295574989406": "LA071589-0076",
  "8279047890050290833": "LA071590-0068",
  "7957892946606506656": "LA072089-0140",
  "-3258521822187353813": "LA073089-0118",
  "-5317016682484429416": "LA080189-0042",
  "9006084258424282356": "LA080790-0111",
  "4906935626095651697": "LA081489-0025",
  "-8583004922842634091": "LA081490-0030",
  "1257206583774818872": "LA081589-0043",
  "4929312183663270114": "LA081890-0039",
  "1869352485876475309": "LA091889-0088",
  "-7133579377137271469": "LA092189-0123",
  "-6769775230398653955": "LA092490-0095",
  "1592254317556901754": "LA092790-0010",
  "8391270740015507488": "LA093089-0076",
  "-6291151232016873303": "LA093089-0126",
  "7724686641748875299": "LA100789-0007",
  "-8374605640522572576": "LA101090-0017",
  "-4319644219028860233": "LA101289-0194",
  "-8264806399583341673": "LA101690-0040",
  "-3070953927201061138": "LA102189-0151",
  "2962120693721374946": "LA102190-0045",
  "-7754743016758548802": "LA103089-0043",
  "-5879029557286454752": "LA103089-0070",
  "-6244290783518684427": "LA110490-0184",
  "6412329741989885947": "LA110589-0082",
  "-1924663062234035810": "LA110590-0038",
  "-4847839437369269996": "LA120290-0163",
  "2768007880283615290": "LA120389-0130",
  "-1876697775694875118": "LA121189-0017",
  "9102070414225307773": "SJMN91-06012224",
  "-393731826536870732": "SJMN91-06071022",
  "-8052937538286045766": "SJMN91-06084228",
  "3179453272125879036": "SJMN91-06105230",
  "7458555112140536661": "SJMN91-06129119",
  "2339004808727266720": "SJMN91-06136305",
  "-7433809000791335134": "SJMN91-06142126",
  "-1081212778573280241": "SJMN91-06143070",
  "1830374626429129750": "SJMN91-06161012",
  "-8033796230994865042": "SJMN91-06169114",
  "-3925530778279705293": "SJMN91-06182091",
  "-2094444445089757520": "SJMN91-06184003",
  "-3013035342874414630": "SJMN91-06184021",
  "-3333052757899145353": "SJMN91-06184088",
  "-3485827343624250982": "SJMN91-06187248",
  "-3441977731453082695": "SJMN91-06189077",
  "-2590097412888502640": "SJMN91-06191081",
  "-3913766184470641509": "SJMN91-06191174",
  "8770317555054084836": "SJMN91-06192123",
  "1759103591020084435": "SJMN91-06193081",
  "5447349091585558431": "SJMN91-06193235",
  "7465323905646887581": "SJMN91-06195131",
  "-5618789424234259791": "SJMN91-06212161",
  "-404288856411468598": "SJMN91-06246065",
  "-4828724155628722931": "SJMN91-06255434",
  "-2289619969743275893": "SJMN91-06276078",
  "4227427670934616301": "SJMN91-06283083",
  "-3716914583266010403": "SJMN91-06290146",
  "-7717295904520918595": "SJMN91-06301029",
  "-3585363709565195691": "SJMN91-06312120",
  "3714677287718428341": "WSJ870123-0101",
  "5614715318820182774": "WSJ870227-0149",
  "-2581992936907808952": "WSJ870306-0171",
  "297082600501824977": "WSJ870501-0141",
  "-2333435718215193912": "WSJ870818-0002",
  "-4840888453321482035": "WSJ870908-0047",
  "3521842674659331373": "WSJ871215-0109",
  "2652182751512194074": "WSJ871216-0037",
  "-875126215466950051": "WSJ880617-0024",
  "8472898828287851521": "WSJ880621-0079",
  "8619913148299361778": "WSJ880923-0163",
  "4830832827305956891": "WSJ890828-0011",
  "-5679657895026377033": "WSJ900418-0193",
  "-7375194762074946605": "WSJ900615-0131",
  "-3691208084237488730": "WSJ900705-0145",
  "5374801068805907442": "WSJ900720-0113",
  "-4168230985199896378": "WSJ900914-0127",
  "896137199384754984": "WSJ900918-0121",
  "-2106468253791446798": "WSJ910107-0139",
  "-757436614391590179": "WSJ910208-0130",
  "-587075739395862550": "WSJ910304-0002",
  "5623995758939940098": "WSJ910304-0005",
  "-3963081333466474148": "WSJ910326-0090",
  "-5147524723907572540": "WSJ910405-0154",
  "-2724448945806332009": "WSJ910529-0003",
  "624509845263600150": "WSJ910607-0063",
  "-5146980560992459601": "WSJ910628-0109",
  "-3121017187320343449": "WSJ910702-0078",
  "-2319399906040846573": "WSJ910709-0115",
  "2705046543261379014": "WSJ910710-0123",
  "-7462829236487515251": "WSJ910710-0148",
  "4352239757395132898": "WSJ910718-0143",
  "6775752490353643554": "WSJ911030-0008",
  "4022428263154205853": "WSJ911031-0012",
  "6544298154403614108": "WSJ911106-0109",
  "-1359665185225664458": "WSJ911121-0136",
  "-5787397293935134839": "WSJ911212-0080",
  "5861021139760903261": "WSJ911224-0085",
  "2897895224457726633": "WSJ920103-0037",
  "4955241817853391574": "WSJ920114-0145",
  "-1919437133587571197": "WSJ920211-0036"
}

class DUCFileRep(CorpusFileRep):
  """
  """

  def __init__(self):
    """
    Constructor.
    """

    super(DUCFileRep, self).__init__()

  def parse_file(self, filepath):
    """
    Parses a corpus file and initialize the object.
    
    @param  filepath: The path of the corpus file to parse.
    @type   filepath: C{string}
    """

    xml_file = open(filepath, "r")
    xml = xml_file.read()
    content = ""

    xml_file.close()

    for line in xml.replace("&amp;", "&").split("\n"):
      if content != "":
        content += " "
      content += re.sub("(<(P|F).*?>)|(<\\/P>)", "", line).strip()
    # XML cleanning

    start_offset = "<START_OFFSET_DUCFileRep>"
    content = start_offset + content
    content = content.replace("</LP>", "</LP>%s"%start_offset)
    content = content.replace("</TEXT>", "</TEXT>%s"%start_offset)
    content = re.sub("%s.*?<LP>(.*?)<\\/LP>"%start_offset, "\\1", content)
    content = re.sub("%s.*?<TEXT>(.*?)<\\/TEXT>"%start_offset, "\\1", content)
    content = re.sub("%s.*"%start_offset, "", content)

    self.set_content(content)

