比较标准答案与分词结果

@param gold
@param pred
962032
public void compare(String gold, String pred)
    {
        String[] wordArray = gold.split("\\s+");
        A_size += wordArray.length;
        String[] predArray = pred.split("\\s+");
        B_size += predArray.length;

        int goldIndex = 0, predIndex = 0;
        int goldLen = 0, predLen = 0;

        while (goldIndex < wordArray.length && predIndex < predArray.length)
        {
            if (goldLen == predLen)
            {
                if (wordArray[goldIndex].equals(predArray[predIndex]))
                {
                    if (dic != null)
                    {
                        if (dic.contains(wordArray[goldIndex]))
                            IV_R += 1;
                        else
                            OOV_R += 1;
                    }
                    A_cap_B_size++;
                    goldLen += wordArray[goldIndex].length();
                    predLen += wordArray[goldIndex].length();
                    goldIndex++;
                    predIndex++;
                }
                else
                {
                    goldLen += wordArray[goldIndex].length();
                    predLen += predArray[predIndex].length();
                    goldIndex++;
                    predIndex++;
                }
            }
            else if (goldLen < predLen)
            {
                goldLen += wordArray[goldIndex].length();
                goldIndex++;
            }
            else
            {
                predLen += predArray[predIndex].length();
                predIndex++;
            }
        }

        if (dic != null)
        {
            for (String word : wordArray)
            {
                if (dic.contains(word))
                    IV += 1;
                else
                    OOV += 1;
            }
        }
    }
126321
def findall_with_pred(predicate, prs):
    
    return sorted((p for p in prs if predicate(p)),
                  key=operator.methodcaller("priority"), reverse=True)
884510
function findPrevNode(firstNode, item, comparer) {
    let ret;
    let prevNode = firstNode;
    // while item > prevNode.value
    while (prevNode != undefined && comparer(prevNode.value, item) > 0) {
        ret = prevNode;
        prevNode = prevNode.next;
    }
    return ret;
}
691867
function dominantAlgorithm(arr, len, preparedStep) {
    const
        colorHash = {},
        divider = 24;

    for (let i = 0; i < len; i += preparedStep) {
        let
            red = arr[i],
            green = arr[i + 1],
            blue = arr[i + 2],
            alpha = arr[i + 3],
            key = Math.round(red / divider) + ',' +
                Math.round(green / divider) + ',' +
                Math.round(blue / divider);

        if (colorHash[key]) {
            colorHash[key] = [
                colorHash[key][0] + red * alpha,
                colorHash[key][1] + green * alpha,
                colorHash[key][2] + blue * alpha,
                colorHash[key][3] + alpha,
                colorHash[key][4] + 1
            ];
        } else {
            colorHash[key] = [red * alpha, green * alpha, blue * alpha, alpha, 1];
        }
    }

    const buffer = Object.keys(colorHash).map(function(key) {
        return colorHash[key];
    }).sort(function(a, b) {
        const
            countA = a[4],
            countB = b[4];

        return countA > countB ?  -1 : countA === countB ? 0 : 1;
    });

    const [redTotal, greenTotal, blueTotal, alphaTotal, count] = buffer[0];

    return alphaTotal ? [
        Math.round(redTotal / alphaTotal),
        Math.round(greenTotal / alphaTotal),
        Math.round(blueTotal / alphaTotal),
        Math.round(alphaTotal / count)
    ] : [0, 0, 0, 0];
}
1037128
def process_pres (out)
      out.gsub /(<pre\b[^>]*?>([\s\S]*?)<\/pre>)\s*/i do
        pre = $2
        m = $1
        pre_compressed = pre.lines.map{ |l| l.gsub(/\s+$/, '') }.join("\n")
        pre_compressed = HtmlPress.entities_compressor pre_compressed
        m.gsub!(pre, pre_compressed)
        reserve m
      end
    end
784488
public static void premultiply(int[] p, int offset, int length) {
		length += offset;
		for (int i = offset; i < length; i++) {
			int rgb = p[i];
			int a = (rgb >> 24) & 0xff;
			int r = (rgb >> 16) & 0xff;
			int g = (rgb >> 8) & 0xff;
			int b = rgb & 0xff;
			float f = a * (1.0f / 255.0f);
			r *= f;
			g *= f;
			b *= f;
			p[i] = (a << 24) | (r << 16) | (g << 8) | b;
		}
	}
519013
function find(items, pred) {
  var len = items.length,
      i = -1;

  while(++i < len) {
    if (pred(items[i], i)) {
      return items[i];
    }
  }

  return null;
}
185240
function binarySearch(arr, pred) {
    let begin   = -1;
    let end     = arr.length;

    while (1 + begin < end) {
        const mi = begin + ((end - begin) >> 1);

        if (pred(arr[mi]))
            end = mi;
        else
            begin = mi;
    }

    return end;
}
1036311
function preLink(scope, element, attr, ctrls) {
    var selectCtrl = ctrls[0];

    element.addClass('_md');     // private md component indicator for styling

    $mdTheming(element);
    element.on('click', clickListener);
    element.on('keypress', keyListener);

    function keyListener(e) {
      if (e.keyCode == 13 || e.keyCode == 32) {
        clickListener(e);
      }
    }

    function clickListener(ev) {
      var option = $mdUtil.getClosest(ev.target, 'md-option');
      var optionCtrl = option && angular.element(option).data('$mdOptionController');
      if (!option || !optionCtrl) return;
      if (option.hasAttribute('disabled')) {
        ev.stopImmediatePropagation();
        return false;
      }

      var optionHashKey = selectCtrl.hashGetter(optionCtrl.value);
      var isSelected = angular.isDefined(selectCtrl.selected[optionHashKey]);

      scope.$apply(function() {
        if (selectCtrl.isMultiple) {
          if (isSelected) {
            selectCtrl.deselect(optionHashKey);
          } else {
            selectCtrl.select(optionHashKey, optionCtrl.value);
          }
        } else {
          if (!isSelected) {
            selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
            selectCtrl.select(optionHashKey, optionCtrl.value);
          }
        }
        selectCtrl.refreshViewValue();
      });
    }
  }
279739
int compare(ByteArraySegment b1, ByteArraySegment b2) {
        assert b1.getLength() == b2.getLength();
        return compare(b1.array(), b1.arrayOffset(), b2.array(), b2.arrayOffset(), b1.getLength());
    }
476503
def evaluate(self, gold):
        
        tagged_sents = self.tag_sents([w for (w, t) in sent] for sent in gold)
        gold_tokens = sum(gold, [])
        test_tokens = sum(tagged_sents, [])
        accuracy = float(sum(x == y for x, y in six.moves.zip(gold_tokens, test_tokens))) / len(test_tokens)
        return accuracy
356328
boolean precedes(final String s1, final String s2) {
    String symbol1 = s1.toLowerCase(Locale.ENGLISH);
    String symbol2 = s2.toLowerCase(Locale.ENGLISH);

    if (!precedenceMap.keySet().contains(symbol1)) {
      return false;
    }

    if (!precedenceMap.keySet().contains(symbol2)) {
      return false;
    }

    int index1 = ((Integer) precedenceMap.get(symbol1)).intValue();
    int index2 = ((Integer) precedenceMap.get(symbol2)).intValue();

    boolean precedesResult = (index1 < index2);

    return precedesResult;
  }
1228540
function(array, pred) {
      return [_.takeWhile(array, pred), _.dropWhile(array, pred)];
    }
1247096
public void prewrite(byte[] b)
    {
        ensureReserve(b.length);
        System.arraycopy(b,0,_buf,_start-b.length,b.length);
        _start-=b.length;
    }
363112
protected void processEdge(int edgeId, int adjNode, int prevEdgeId) {
        EdgeIteratorState iter = graph.getEdgeIteratorState(edgeId, adjNode);
        distance += iter.getDistance();
        time += weighting.calcMillis(iter, false, prevEdgeId);
        addEdge(edgeId);
    }
913304
public void evaluate(Tree guess, Tree gold, PrintWriter pw) {
    evaluate(guess, gold, pw, 1.0);
  }
905542
public int getGoldConfigIdxPred(int factorId) {
        VarSet vars = VarSet.getVarsOfType(fgLatPred.getFactor(factorId).getVars(), VarType.PREDICTED);
        return goldConfig.getConfigIndexOfSubset(vars);
    }