Пример #1
0
 def count(self, source, expectedsource, target=None, expectedtarget=None):
     """simple helper to check the respective word counts"""
     poelement = po.pounit(source)
     if target is not None:
         poelement.target = target
     wordssource, wordstarget = statsdb.wordsinunit(poelement)
     print('Source (expected=%d; actual=%d): "%s"' % (expectedsource, wordssource, source))
     assert wordssource == expectedsource
     if target is not None:
         print('Target (expected=%d; actual=%d): "%s"' % (expectedtarget, wordstarget, target))
         assert wordstarget == expectedtarget
Пример #2
0
 def count(self, source, expectedsource, target=None, expectedtarget=None):
     """simple helper to check the respective word counts"""
     poelement = po.pounit(source)
     if target is not None:
         poelement.target = target
     wordssource, wordstarget = statsdb.wordsinunit(poelement)
     print('Source (expected=%d; actual=%d): "%s"' % (expectedsource, wordssource, source))
     assert wordssource == expectedsource
     if target is not None:
         print('Target (expected=%d; actual=%d): "%s"' % (expectedtarget, wordstarget, target))
         assert wordstarget == expectedtarget
Пример #3
0
def should_output_store(store, threshold):
    """Check if the percent of translated source words more than or equal to
    the given threshold.
    """

    if not threshold:
        return True

    from translate.storage import statsdb

    units = filter(lambda unit: unit.istranslatable(), store.units)
    translated = filter(lambda unit: unit.istranslated(), units)
    wordcounts = dict(map(lambda unit: (unit, statsdb.wordsinunit(unit)), units))
    sourcewords = lambda elementlist: sum(map(lambda unit: wordcounts[unit][0], elementlist))
    tranlated_count = sourcewords(translated)
    total_count = sourcewords(units)
    percent = tranlated_count * 100 / total_count

    return percent >= threshold
Пример #4
0
def should_output_store(store, threshold):
    """Check if the percent of translated source words more than or equal to
    the given threshold.
    """

    if not threshold:
        return True

    from translate.storage import statsdb

    units = [unit for unit in store.units if unit.istranslatable()]
    translated = [unit for unit in units if unit.istranslated()]
    wordcounts = dict([(unit, statsdb.wordsinunit(unit)) for unit in units])
    sourcewords = lambda elementlist: sum([wordcounts[unit][0] for unit in elementlist])
    tranlated_count = sourcewords(translated)
    total_count = sourcewords(units)
    percent = tranlated_count * 100 / total_count

    return percent >= threshold
Пример #5
0
def calcstats_old(filename):
    """This is the previous implementation of calcstats() and is left for
    comparison and debuging purposes."""
    # ignore totally blank or header units
    try:
        store = factory.getobject(filename)
    except ValueError as e:
        logger.warning(e)
        return {}
    units = filter(lambda unit: unit.istranslatable(), store.units)
    translated = translatedmessages(units)
    fuzzy = fuzzymessages(units)
    review = filter(lambda unit: unit.isreview(), units)
    untranslated = untranslatedmessages(units)
    wordcounts = dict(
        map(lambda unit: (unit, statsdb.wordsinunit(unit)), units))
    sourcewords = lambda elementlist: sum(
        map(lambda unit: wordcounts[unit][0], elementlist))
    targetwords = lambda elementlist: sum(
        map(lambda unit: wordcounts[unit][1], elementlist))
    stats = {}

    # units
    stats["translated"] = len(translated)
    stats["fuzzy"] = len(fuzzy)
    stats["untranslated"] = len(untranslated)
    stats["review"] = len(review)
    stats["total"] = stats["translated"] + \
                     stats["fuzzy"] + \
                     stats["untranslated"]

    # words
    stats["translatedsourcewords"] = sourcewords(translated)
    stats["translatedtargetwords"] = targetwords(translated)
    stats["fuzzysourcewords"] = sourcewords(fuzzy)
    stats["untranslatedsourcewords"] = sourcewords(untranslated)
    stats["reviewsourcewords"] = sourcewords(review)
    stats["totalsourcewords"] = stats["translatedsourcewords"] + \
                                stats["fuzzysourcewords"] + \
                                stats["untranslatedsourcewords"]
    return stats
Пример #6
0
def calcstats_old(filename):
    """This is the previous implementation of calcstats() and is left for
    comparison and debuging purposes.
    """
    # ignore totally blank or header units
    try:
        store = factory.getobject(filename)
    except ValueError as e:
        logger.warning(e)
        return {}
    units = [unit for unit in store.units if unit.istranslatable()]
    translated = translatedmessages(units)
    fuzzy = fuzzymessages(units)
    review = [unit for unit in units if unit.isreview()]
    untranslated = untranslatedmessages(units)
    wordcounts = {id(unit): statsdb.wordsinunit(unit) for unit in units}
    sourcewords = lambda elementlist: sum(wordcounts[id(unit)][0]
                                          for unit in elementlist)
    targetwords = lambda elementlist: sum(wordcounts[id(unit)][1]
                                          for unit in elementlist)
    stats = {}

    # units
    stats["translated"] = len(translated)
    stats["fuzzy"] = len(fuzzy)
    stats["untranslated"] = len(untranslated)
    stats["review"] = len(review)
    stats[
        "total"] = stats["translated"] + stats["fuzzy"] + stats["untranslated"]

    # words
    stats["translatedsourcewords"] = sourcewords(translated)
    stats["translatedtargetwords"] = targetwords(translated)
    stats["fuzzysourcewords"] = sourcewords(fuzzy)
    stats["untranslatedsourcewords"] = sourcewords(untranslated)
    stats["reviewsourcewords"] = sourcewords(review)
    stats["totalsourcewords"] = (stats["translatedsourcewords"] +
                                 stats["fuzzysourcewords"] +
                                 stats["untranslatedsourcewords"])
    return stats
Пример #7
0
def calcstats_old(filename):
    """This is the previous implementation of calcstats() and is left for
    comparison and debuging purposes.
    """
    # ignore totally blank or header units
    try:
        store = factory.getobject(filename)
    except ValueError as e:
        logger.warning(e)
        return {}
    units = [unit for unit in store.units if unit.istranslatable()]
    translated = translatedmessages(units)
    fuzzy = fuzzymessages(units)
    review = [unit for unit in units if unit.isreview()]
    untranslated = untranslatedmessages(units)
    wordcounts = dict((id(unit), statsdb.wordsinunit(unit)) for unit in units)
    sourcewords = lambda elementlist: sum(wordcounts[id(unit)][0] for unit in elementlist)
    targetwords = lambda elementlist: sum(wordcounts[id(unit)][1] for unit in elementlist)
    stats = {}

    # units
    stats["translated"] = len(translated)
    stats["fuzzy"] = len(fuzzy)
    stats["untranslated"] = len(untranslated)
    stats["review"] = len(review)
    stats["total"] = (stats["translated"] +
                      stats["fuzzy"] +
                      stats["untranslated"])

    # words
    stats["translatedsourcewords"] = sourcewords(translated)
    stats["translatedtargetwords"] = targetwords(translated)
    stats["fuzzysourcewords"] = sourcewords(fuzzy)
    stats["untranslatedsourcewords"] = sourcewords(untranslated)
    stats["reviewsourcewords"] = sourcewords(review)
    stats["totalsourcewords"] = (stats["translatedsourcewords"] +
                                 stats["fuzzysourcewords"] +
                                 stats["untranslatedsourcewords"])
    return stats
def calcstats_old(filename):
    """This is the previous implementation of calcstats() and is left for
    comparison and debuging purposes."""
    # ignore totally blank or header units
    try:
        store = factory.getobject(filename)
    except ValueError, e:
        print str(e)
        return {}
    units = filter(lambda unit: not unit.isheader(), store.units)
    translated = translatedmessages(units)
    fuzzy = fuzzymessages(units)
    review = filter(lambda unit: unit.isreview(), units)
    untranslated = untranslatedmessages(units)
    wordcounts = dict(map(lambda unit: (unit, statsdb.wordsinunit(unit)), units))
    sourcewords = lambda elementlist: sum(map(lambda unit: wordcounts[unit][0], elementlist))
    targetwords = lambda elementlist: sum(map(lambda unit: wordcounts[unit][1], elementlist))
    stats = {}

    #units
    stats["translated"] = len(translated)
    stats["fuzzy"] = len(fuzzy)
    stats["untranslated"] = len(untranslated)
    stats["review"] = len(review)
    stats["total"] = stats["translated"] + stats["fuzzy"] + stats["untranslated"]

    #words
    stats["translatedsourcewords"] = sourcewords(translated)
    stats["translatedtargetwords"] = targetwords(translated)
    stats["fuzzysourcewords"] = sourcewords(fuzzy)
Пример #9
0
def calcstats_old(filename):
    """This is the previous implementation of calcstats() and is left for
    comparison and debuging purposes."""
    # ignore totally blank or header units
    try:
        store = factory.getobject(filename)
    except ValueError, e:
        print str(e)
        return {}
    units = filter(lambda unit: unit.istranslatable(), store.units)
    translated = translatedmessages(units)
    fuzzy = fuzzymessages(units)
    review = filter(lambda unit: unit.isreview(), units)
    untranslated = untranslatedmessages(units)
    wordcounts = dict(
        map(lambda unit: (unit, statsdb.wordsinunit(unit)), units))
    sourcewords = lambda elementlist: sum(
        map(lambda unit: wordcounts[unit][0], elementlist))
    targetwords = lambda elementlist: sum(
        map(lambda unit: wordcounts[unit][1], elementlist))
    stats = {}

    #units
    stats["translated"] = len(translated)
    stats["fuzzy"] = len(fuzzy)
    stats["untranslated"] = len(untranslated)
    stats["review"] = len(review)
    stats["total"] = stats["translated"] + \
                     stats["fuzzy"] + \
                     stats["untranslated"]