本文整理汇总了Java中org.simmetrics.StringMetric类的典型用法代码示例。如果您正苦于以下问题:Java StringMetric类的具体用法?Java StringMetric怎么用?Java StringMetric使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringMetric类属于org.simmetrics包,在下文中一共展示了StringMetric类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: identity
import org.simmetrics.StringMetric; //导入依赖的package包/类
/**
* Returns an identity string similarity metric. The metric returns 1.0 when
* the inputs are equals, and 0.0 when they're not.
*
* @return an identity similarity metric
*
* @see Identity
*/
public static StringMetric identity() {
return new StringMetric() {
private final Identity<String> metric = new Identity<>();
@Override
public float compare(String a, String b) {
return metric.compare(a, b);
}
@Override
public String toString() {
return metric.toString();
}
};
}
开发者ID:janmotl,项目名称:linkifier,代码行数:25,代码来源:StringMetrics.java
示例2: getSimilarity
import org.simmetrics.StringMetric; //导入依赖的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;
}
开发者ID:gizemsogancioglu,项目名称:biosses,代码行数:20,代码来源:SentenceVectorsBasedSimilarity.java
示例3: build
import org.simmetrics.StringMetric; //导入依赖的package包/类
@Override
public StringMetric build() {
if (simplifiers.isEmpty()) {
return create(metric);
}
return create(metric, chainSimplifiers());
}
开发者ID:janmotl,项目名称:linkifier,代码行数:9,代码来源:StringMetricBuilder.java
示例4: getSmsSimilarityScore
import org.simmetrics.StringMetric; //导入依赖的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;
}
}
开发者ID:xRahul,项目名称:GroupingMessages,代码行数:12,代码来源:TrainSms.java
示例5: similarityStringsLevenshstein
import org.simmetrics.StringMetric; //导入依赖的package包/类
/**
* Calculate the similarity of two strings. At the moment Cosine
* distance is used for that. The returned float value is limited to
* 0 all characters different and 1 all are the same. -1 is returned if
* stringA is empty.
* @param stringA
* @param stringB
* @return The returned float value is limited to 0 all characters
* different and 1 all are the same. -1 is returned if stringA is empty.
*/
public static float similarityStringsLevenshstein(String stringA, String stringB) {
if(stringA.equals("")){
return -1;
}else{
StringMetric metric = with(new Levenshtein())
.simplify(Simplifiers.removeNonWord())
.simplify(Simplifiers.toLowerCase()).build();
return metric.compare(stringA, stringB);
}
}
开发者ID:mxhdev,项目名称:SQLChecker,代码行数:23,代码来源:CalculateSimilarity.java
示例6: similarityStringsCosine
import org.simmetrics.StringMetric; //导入依赖的package包/类
public static float similarityStringsCosine(String stringA, String stringB) {
if(stringA.equals("")){
return -1;
}else{
StringMetric metric =
with(new CosineSimilarity<String>())
.simplify(Simplifiers.toLowerCase())
.tokenize(Tokenizers.whitespace())
.build();
return metric.compare(stringA, stringB);
}
}
开发者ID:mxhdev,项目名称:SQLChecker,代码行数:15,代码来源:CalculateSimilarity.java
示例7: testDistances
import org.simmetrics.StringMetric; //导入依赖的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"));
}
开发者ID:AskNowQA,项目名称:cubeqa,代码行数:11,代码来源:ComponentPropertyTest.java
示例8: create
import org.simmetrics.StringMetric; //导入依赖的package包/类
public static StringMetric create(Metric<String> metric) {
return org.simmetrics.metrics.StringMetrics.create(metric);
}
开发者ID:janmotl,项目名称:linkifier,代码行数:4,代码来源:StringMetrics.java
示例9: createForListMetric
import org.simmetrics.StringMetric; //导入依赖的package包/类
public static StringMetric createForListMetric(Metric<List<String>> metric, Simplifier simplifier,
Tokenizer tokenizer) {
return org.simmetrics.metrics.StringMetrics.createForListMetric(metric,simplifier, tokenizer);
}
开发者ID:janmotl,项目名称:linkifier,代码行数:6,代码来源:StringMetrics.java
示例10: createForSetMetric
import org.simmetrics.StringMetric; //导入依赖的package包/类
public static StringMetric createForSetMetric(Metric<Set<String>> metric, Simplifier simplifier,
Tokenizer tokenizer) {
return org.simmetrics.metrics.StringMetrics.createForSetMetric(metric,simplifier, tokenizer);
}
开发者ID:janmotl,项目名称:linkifier,代码行数:5,代码来源:StringMetrics.java
示例11: createForMultisetMetric
import org.simmetrics.StringMetric; //导入依赖的package包/类
public static StringMetric createForMultisetMetric(Metric<Multiset<String>> metric, Simplifier simplifier,
Tokenizer tokenizer) {
return org.simmetrics.metrics.StringMetrics.createForMultisetMetric(metric,simplifier, tokenizer);
}
开发者ID:janmotl,项目名称:linkifier,代码行数:5,代码来源:StringMetrics.java
示例12: calculateSimilarityScoreForGivenPair
import org.simmetrics.StringMetric; //导入依赖的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;
}
开发者ID:gizemsogancioglu,项目名称:biosses,代码行数:58,代码来源:SSESService.java
示例13: getSimilarity
import org.simmetrics.StringMetric; //导入依赖的package包/类
public double getSimilarity(String sentence1, String sentence2) throws IOException {
StringMetric metric = StringMetrics.needlemanWunch();
float result = metric.compare(sentence1, sentence2); //0.4767
return result;
}
开发者ID:gizemsogancioglu,项目名称:biosses,代码行数:7,代码来源:SimMetricFunctions.java
示例14: processTypoCustomProperties
import org.simmetrics.StringMetric; //导入依赖的package包/类
protected String processTypoCustomProperties(String liferayVersion,
Properties customPortalProperties) throws IOException {
if (customPortalProperties.isEmpty()) {
return StringPool.BLANK;
}
SortedSet<String> customKeys = new TreeSet<String>(
customPortalProperties.stringPropertyNames());
StringBuilder stringBuilder = new StringBuilder();
boolean processedContext = false;
StringMetric metric = StringMetricBuilder
.with(new CosineSimilarity<String>())
.simplify(new Case.Lower(Locale.ENGLISH))
.simplify(new WordCharacters()).tokenize(new Whitespace())
.tokenize(new QGram(2)).build();
Set<String> defaultKeys = getProperyKeys(liferayVersion);
for (String customKey : customKeys) {
float distance = 0;
String key = null;
for (String defaultKey : defaultKeys) {
float temp = metric.compare(defaultKey, customKey);
if (temp > distance) {
distance = temp;
key = defaultKey;
}
}
if (distance > 0.9) {
if (!processedContext) {
stringBuilder.append("##\n## Typo properties\n##");
stringBuilder.append("\n\n");
stringBuilder.append(" #\n");
stringBuilder
.append(" # The properties listed below looks like that has a typo in its declaration\n");
stringBuilder
.append(" # which means that they don't have any influence in how Liferay is configured.\n");
stringBuilder
.append(" # The system suggested the correct property name in the comments.\n");
stringBuilder.append(" #");
processedContext = true;
}
String value = fixLineBreak(customPortalProperties
.getProperty(customKey));
stringBuilder.append("\n");
stringBuilder.append(" #" + key + "=" + value);
stringBuilder.append("\n");
stringBuilder.append(" " + customKey + "=" + value);
customPortalProperties.remove(customKey);
}
}
if (processedContext) {
stringBuilder.append("\n");
stringBuilder.append("\n");
}
return stringBuilder.toString();
}
开发者ID:tmoreira2020,项目名称:portal-properties-prettier-app,代码行数:65,代码来源:PortalPropertiesPrettier.java
示例15: create
import org.simmetrics.StringMetric; //导入依赖的package包/类
/**
* Either constructs a new string similarity metric or returns the original
* metric.
*
* @param metric
* a metric for strings
*
* @return a similarity metric.
*
* @deprecated Use {@link StringMetricBuilder} in favor of directly
* constructing a metric.
*/
@Deprecated
public static StringMetric create(Metric<String> metric) {
if (metric instanceof StringMetric) {
return (StringMetric) metric;
}
return new ForString(metric);
}
开发者ID:janmotl,项目名称:linkifier,代码行数:21,代码来源:StringMetrics.java
示例16: createForMultisetMetric
import org.simmetrics.StringMetric; //导入依赖的package包/类
/**
* Creates a new composite string similarity metric.The tokenizer is used to
* tokenize the simplified strings. The set metric compares the the tokens.
*
* @param metric
* a list metric
* @param simplifier
* a simplifier
* @param tokenizer
* a tokenizer
* @return a new composite similarity metric
*
* @throws NullPointerException
* when either metric, simplifier or tokenizer are null
*
* @see StringMetricBuilder
*
* @deprecated Use {@link StringMetricBuilder} in favor of directly
* constructing a metric.
*/
@Deprecated
public static StringMetric createForMultisetMetric(
Metric<Multiset<String>> metric, Simplifier simplifier,
Tokenizer tokenizer) {
return new ForMultisetWithSimplifier(metric, simplifier, tokenizer);
}
开发者ID:janmotl,项目名称:linkifier,代码行数:27,代码来源:StringMetrics.java
示例17: jaccardSimilarity
import org.simmetrics.StringMetric; //导入依赖的package包/类
public static float jaccardSimilarity(String sentence1, String sentence2){
StringMetric metric = StringMetrics.jaccard();
float result = metric.compare(sentence1, sentence2); //0.4767
return result;
}
开发者ID:gizemsogancioglu,项目名称:biosses,代码行数:8,代码来源:SimMetricFunctions.java
示例18: cosineSimilarity
import org.simmetrics.StringMetric; //导入依赖的package包/类
/**
* Returns a cosine similarity metric over tokens in a string. The tokens
* are created by splitting the string on whitespace.
*
* @return a cosine similarity metric
*
* @see CosineSimilarity
*/
public static StringMetric cosineSimilarity() {
return with(new CosineSimilarity<String>())
.tokenize(whitespace())
.build();
}
开发者ID:janmotl,项目名称:linkifier,代码行数:14,代码来源:StringMetrics.java
示例19: blockDistance
import org.simmetrics.StringMetric; //导入依赖的package包/类
/**
* Returns a block distance similarity metric over tokens in a string. The
* tokens are created by splitting the string on whitespace.
*
* @return a block distance metric
*
* @see BlockDistance
*/
public static StringMetric blockDistance() {
return with(new BlockDistance<String>()).tokenize(whitespace()).build();
}
开发者ID:janmotl,项目名称:linkifier,代码行数:12,代码来源:StringMetrics.java
示例20: damerauLevenshtein
import org.simmetrics.StringMetric; //导入依赖的package包/类
/**
* Returns a Damerau-Levenshtein similarity metric over tokens in a string.
* The tokens are created by splitting the string on whitespace.
*
* @return a Damerau-Levenshtein metric
*
* @see DamerauLevenshtein
*/
public static StringMetric damerauLevenshtein() {
return new DamerauLevenshtein();
}
开发者ID:janmotl,项目名称:linkifier,代码行数:12,代码来源:StringMetrics.java
注:本文中的org.simmetrics.StringMetric类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论