def country_strategy_papers(doc):
    countries = all_countries(doc)

    # Is there a country strategy paper for each
    # country? (Based on the list of countries that
    # have an active country budget.)

    if len(countries) == 0:
        return 0.00

    total_countries = len(countries)
    strategy_papers = doc.xpath("//document-link[category/@code]")

    countrycodelist = dqcodelists.reformatCodelist("countriesbasic")

    for code, name in countries.items():
        # Some donors have not provided the name of the country; the
        # country code could theoretically be looked up to find the
        # name of the country
        name = getCountryName(code, name, countrycodelist)
        for strategy_paper in strategy_papers:
            if name is not None:
                title = strategy_paper.find("title").text.upper()
                name = name.upper()
                if re.compile("(.*)" + name + "(.*)").match(title):
                    try:
                        countries.pop(code)
                    except Exception:
                        pass
    print "Remaining countries are", countries
    return 100 - (float(len(countries)) / float(total_countries)) * 100
Example #2
0
 def get_doc_from_xml(xml):
     if xml == None:
         return []
     document_category_codes = dqcodelists.reformatCodelist('DocumentCategory')
     document_links = sample_work.DocumentLinks(work_item["xml_data"], 
                                        document_category_codes)
     docs = [ dl.to_dict() for dl in document_links.get_links() ]
     return docs
Example #3
0
def country_strategy_papers(doc):
    countries = all_countries(doc)

    # Is there a country strategy paper for each 
    # country? (Based on the list of countries that
    # have an active country budget.)

    if len(countries)==0:
        return 0.00

    total_countries = len(countries)
    strategy_papers = doc.xpath("//document-link[category/@code='B03']")

    countrycodelist = dqcodelists.reformatCodelist("countriesbasic")

    for code, name in countries.items():
        # Some donors have not provided the name of the country; the
        # country code could theoretically be looked up to find the 
        # name of the country
        name = getCountryName(code, name, countrycodelist)
        for strategy_paper in strategy_papers:
            recipient = strategy_paper.find('recipient-country')
            if recipient is not None:
                if recipient.get('code').lower() == code.lower():
                    try:
                        countries.pop(code)
                    except Exception:
                        pass
                    continue
            if name is not None:
                title = strategy_paper.find('title')
                if not title.text or not title.text.strip():
                    title = title.find('narrative')
                if re.search(name, title.text, flags=re.IGNORECASE):
                    try:
                        countries.pop(code)
                    except Exception:
                        pass
    print "Remaining countries are", countries
    return 100-(float(len(countries))/float(total_countries))*100