Java examples for java.lang:Math Vector
Perform a word match-based scoring between two vectors
//package com.java2s; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class Main { /**//from w w w.ja va2 s . c o m * * Perform a word match-based scoring between two vectors * * @param vector1 * @param vector2 * @return score */ public static double computeWordMatchBasedScore( Map<String, Integer> vector1, Map<String, Integer> vector2) { double score = 0.0; score = ((double) match(vector1, vector2).size()) / vector2.size(); return score; } /** * * Matches vector 1 with vector 2 and returns the vector of matched strings * * @param vector1 * @param vector2 * @return dotproduct */ public static Map<String, Integer> match(Map<String, Integer> vector1, Map<String, Integer> vector2) { Map<String, Integer> matchedVector = new HashMap<String, Integer>(); Set<String> vector1Vocab = vector1.keySet(); Iterator<String> iter = vector1Vocab.iterator(); Integer vector1Freq; Integer vector2Freq; String word = null; while (iter.hasNext()) { word = iter.next(); vector1Freq = vector1.get(word); if (vector2.containsKey(word)) { vector2Freq = vector2.get(word); matchedVector.put( word, new Integer(Math.min(vector1Freq.intValue(), vector2Freq.intValue()))); } } return matchedVector; } }