本文整理汇总了Java中org.simmetrics.metrics.StringMetrics类的典型用法代码示例。如果您正苦于以下问题:Java StringMetrics类的具体用法?Java StringMetrics怎么用?Java StringMetrics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringMetrics类属于org.simmetrics.metrics包,在下文中一共展示了StringMetrics类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSimilarity
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
public double getSimilarity(String sentence1, String sentence2){
double predictedScore = 0;
if (PARAGRAPHVECS != null) {
try {
INDArray inferredVectorA = produceParagraphVectorOfGivenSentence(sentence1);
INDArray inferredVectorB = produceParagraphVectorOfGivenSentence(sentence2);
predictedScore = Transforms.cosineSim(inferredVectorA, inferredVectorB);
} catch (Exception e) {
logger.error("No word is matched with the given sentence and any sentence in training set - model file. " + sentence1
+ ";" + sentence2);
System.out.println("No word is matched with the given sentence and any sentence in training set - model file. " + sentence1
+ ";" + sentence2);
StringMetric metric = StringMetrics.qGramsDistance();
predictedScore = metric.compare(sentence1, sentence2);
}
}
return predictedScore;
}
示例2: getSmsSimilarityScore
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
private static double getSmsSimilarityScore(String algo, String sms1, String sms2) {
Method method;
try {
method = StringMetrics.class.getMethod(algo);
StringMetric m = (StringMetric) method.invoke(null);
return m.compare(sms1, sms2);
} catch (IllegalAccessException | InvocationTargetException | SecurityException | NoSuchMethodException e) {
Log.e("GM/simError", e.toString());
return 0.0;
}
}
示例3: internalEvaluate
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
@Override
protected Value internalEvaluate(final Value... values) throws ExpressionEvaluationException {
final String firstString = assertStringLiteral(values[0]).stringValue();
final String secondString = assertStringLiteral(values[1]).stringValue();
return literal(StringMetrics.overlapCoefficient().compare(firstString, secondString));
}
示例4: testDistances
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
@Ignore
@Test public void testDistances()
{
StringMetric similarity = StringMetrics.qGramsDistance();
System.out.println(similarity.compare("amountsextended","amountsextended"));
System.out.println(similarity.compare("amounts extended","extended amounts"));
System.out.println(similarity.compare("amountsextended","extendedamounts"));
System.out.println(similarity.compare("nestle","nestlé"));
System.out.println(similarity.compare("nerf","berg"));
}
示例5: calculateSimilarityScoreForGivenPair
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
@WebMethod
public double calculateSimilarityScoreForGivenPair(String s1, String s2, int methodType) throws SLIB_Exception, IOException {
double similarityScore = 0;
System.out.println("REQUEST has been received for: " + s1 + " " + s2 + " " + methodType);
String preprocessedS1 = fileOperations.removeStopWordsFromSentence(s1, stopWordsList);
String preprocessedS2 = fileOperations.removeStopWordsFromSentence(s2, stopWordsList);
String example_1 = "It has recently been shown that Craf is essential for Kras G12D-induced NSCLC.";
String example_2 = "It has recently become evident that Craf is essential for the onset of Kras-driven non-small cell lung cancer.";
switch (methodType){
case 1:
//WordNet-based similarity was selected
CombinedOntologyMethod measureOfWordNet = new CombinedOntologyMethod(stopWordsList);
similarityScore = measureOfWordNet.getSimilarityForWordnet(s1, s2);
System.out.println("SCOREOFWORDNET: " + similarityScore);
break;
case 2:
//UMLS-based similarity option was selected
CombinedOntologyMethod measureOfUmls = new CombinedOntologyMethod(stopWordsList);
similarityScore = measureOfUmls.getSimilarityForUMLS(s1, s2);
System.out.println("SCOREOFUMLS: " + similarityScore);
break;
case 3:
//COMBINED ontology based similarity option was selected
CombinedOntologyMethod score_wordnet = new CombinedOntologyMethod(stopWordsList);
double score_1 =score_wordnet.getSimilarityForWordnet(s1, s2);
double score2 = score_wordnet.getSimilarityForUMLS(s1,s2);
similarityScore = (score2+score_1)/2;
System.out.println("SCOREOFCOMBINED: " + similarityScore);
break;
case 4:
//qgram string similarity option was selected.
StringMetric metric = StringMetrics.qGramsDistance();
similarityScore = metric.compare(preprocessedS1, preprocessedS2); //0.4767
System.out.println("SCOREOFQGRAM: "+similarityScore);
break;
case 5:
//paragraph vector model based similarity was selected as an option.
SentenceVectorsBasedSimilarity sentenceVectorsBasedSimilarity = new SentenceVectorsBasedSimilarity();
similarityScore = sentenceVectorsBasedSimilarity.getSimilarity(preprocessedS1, preprocessedS2);
System.out.println("SCOREOFPARAGRAPHVEC:" + similarityScore);
break;
case 6:
//Supervised Semantic Similarity was selected from the options list.
LinearRegressionMethod linearRegressionMethod = new LinearRegressionMethod();
similarityScore = linearRegressionMethod.getSimilarity(preprocessedS1, preprocessedS2);
System.out.println("SCOREOFSUPERVISED: " + similarityScore);
break;
}
return similarityScore;
}
示例6: getSimilarity
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
public double getSimilarity(String sentence1, String sentence2) throws IOException {
StringMetric metric = StringMetrics.needlemanWunch();
float result = metric.compare(sentence1, sentence2); //0.4767
return result;
}
示例7: Lookup
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
protected Lookup() {
super();
metric = StringMetrics.levenshtein();
}
示例8: jaccardSimilarity
import org.simmetrics.metrics.StringMetrics; //导入依赖的package包/类
public static float jaccardSimilarity(String sentence1, String sentence2){
StringMetric metric = StringMetrics.jaccard();
float result = metric.compare(sentence1, sentence2); //0.4767
return result;
}