Skip to content

Instantly share code, notes, and snippets.

@kreeben
Last active September 21, 2018 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreeben/13faea4b3e68dad6c9a50006a3b4675a to your computer and use it in GitHub Desktop.
Save kreeben/13faea4b3e68dad6c9a50006a3b4675a to your computer and use it in GitHub Desktop.
Comparing text with Resin
using System;
using Sir.Store;
namespace Sir.StringCompare
{
class Program
{
static void Main(string[] args)
{
var document1 = args[0];
var document2 = args[1];
var docNode1 = new VectorNode(document1);
var docNode2 = new VectorNode(document2);
var docAngle = docNode1.TermVector.CosAngle(docNode2.TermVector);
if (docAngle >= VectorNode.IdenticalAngle)
{
Console.Write("{0} is very similar to {1} ({2}%)", document1, document2, docAngle*100);
}
else
{
var tokenizer = new LatinTokenizer();
var index1 = new VectorNode();
foreach (var token in tokenizer.Tokenize(document1))
{
index1.Add(new VectorNode(token));
}
float score = 0;
var count = 0;
foreach (var token in tokenizer.Tokenize(document2))
{
var node = index1.ClosestMatch(token, skipDirtyNodes:false);
score += node.Highscore;
count++;
}
var similarity = (score / count) * 100;
Console.WriteLine("{0} is {1}% similar to {2}", document1, similarity, document2);
Console.Read();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment