Beispiel #1
0
    private CommaAndPeriodInfo CountCommasAndPeriods(string s)
    {
        char[] characters  = s.ToCharArray();
        int    periodCount = 0;
        int    commaCount  = 0;
        int    totalCommas = 0;

        foreach (char c in characters)
        {
            if (c == ',')
            {
                if (commaCount < 2)
                {
                    commaCount++;
                    totalCommas++;
                }
            }
            else
            {
                if (c == '.')
                {
                    periodCount++;
                }
                commaCount = 0;
            }
        }
        CommaAndPeriodInfo capI = new CommaAndPeriodInfo();

        capI.setCommaNumber(totalCommas);
        capI.setPeriodNumber(periodCount);
        return(capI);
    }
Beispiel #2
0
    private void FilterShortStrings(string[] text)
    {
        var findings = new Queue <string>();

        foreach (string s in text)
        {
            int length = s.Length;

            CommaAndPeriodInfo result = CountCommasAndPeriods(s);
            int commaNumber           = result.getCommaNumber();
            int periodNumber          = result.getPeriodNumber();
            //every Comma extends the maxlength by 2 (because commas themselves translate to a conjunctor => their own number + 1 extra word for each comma)
            //every period extends the maclengt by 1 (have no effect on the length of the translation)
            if (length > 2 && length <= maxTextLength + (2 * commaNumber) + periodNumber)
            {
                findings.Enqueue(s);
            }
        }

        if (findings.Count > 0)
        {
            knowledge.Enqueue(translator.translateText(findings.Dequeue()));
        }
    }