Skip to content

Commit ac8ad3b

Browse files
committed
added docs
1 parent cd48234 commit ac8ad3b

File tree

8 files changed

+926
-32
lines changed

8 files changed

+926
-32
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# string-metrics
22

3-
String metrics and phonetic algorithms for Crystal:
3+
String metric algorithms for Crystal:
44
* [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
55
* [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance)
66
* [Damerau–Levenshtein distance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance)
@@ -21,13 +21,14 @@ dependencies:
2121
2222
```crystal
2323
require "string-metrics"
24-
```
25-
26-
TODO: Write usage instructions here
2724

28-
## Development
25+
StringMetrics.damerau_levenshtein("char", "hcar") == 1
26+
StringMetrics.hamming("Micro", "Macro") == 1
27+
StringMetrics.jaro("MARTHA", "MARHTA").round(2) == 0.94
28+
StringMetrics.jaro_winkler("MARTHA", "MARHTA").round(2) == 0.96
29+
StringMetrics.levenshtein("Car", "Char") == 1
30+
```
2931

30-
TODO: Write development instructions here
3132

3233
## Contributing
3334

docs/StringMetrics.html

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta id="repository-name" content="github.com/mlobl/string-metrics">
6+
<link href="css/style.css" rel="stylesheet" type="text/css" />
7+
<script type="text/javascript" src="js/doc.js"></script>
8+
<title>StringMetrics - github.com/mlobl/string-metrics</title>
9+
</head>
10+
<body>
11+
12+
<div id="types-list">
13+
<div id="search-box">
14+
<input type="search" id="search-input" placeholder="Search...">
15+
</div>
16+
17+
<ul>
18+
<li><a href="index.html">README</a></li>
19+
</ul>
20+
21+
<ul>
22+
23+
<li class=" current" data-id="github.com/mlobl/string-metrics/StringMetrics" data-name="stringmetrics">
24+
<a href="StringMetrics.html">StringMetrics</a>
25+
26+
</li>
27+
28+
</ul>
29+
30+
</div>
31+
32+
<div id="main-content">
33+
<h1 class="type-name">
34+
35+
<span class="kind">module</span> StringMetrics
36+
37+
</h1>
38+
39+
40+
41+
42+
43+
<h2>Overview</h2>
44+
45+
<p>A module containing a collection of well known string metric algorithms</p>
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
<h2>Defined in:</h2>
61+
62+
63+
<a href="https://github.com/mlobl/string-metrics/blob/cd482346d54b593f0e62779e4d9fa8b3c1386a8b/src/string-metrics/version.cr#L1" target="_blank">string-metrics/version.cr</a>
64+
65+
<br/>
66+
67+
68+
<a href="https://github.com/mlobl/string-metrics/blob/cd482346d54b593f0e62779e4d9fa8b3c1386a8b/src/string-metrics.cr#L4" target="_blank">string-metrics.cr</a>
69+
70+
<br/>
71+
72+
73+
74+
75+
76+
<h2>Constant Summary</h2>
77+
78+
<dl>
79+
80+
<dt class="entry-const" id="VERSION">
81+
<strong>VERSION</strong> = <code><span class="s">&quot;0.1.0&quot;</span></code>
82+
</dt>
83+
84+
85+
</dl>
86+
87+
88+
89+
90+
91+
<h2>Class Method Summary</h2>
92+
<ul class="list-summary">
93+
94+
<li class="entry-summary">
95+
<a href="#damerau_levenshtein%28s1%3AString%2Cs2%3AString%29%3AInt-class-method" class="signature"><strong>.damerau_levenshtein</strong>(s1 : String, s2 : String) : Int</a>
96+
97+
<div class="summary"><p>A variation of the Levenshtein distance, this counts transpositions as a single edit.</p></div>
98+
99+
</li>
100+
101+
<li class="entry-summary">
102+
<a href="#hamming%28s1%3AString%2Cs2%3AString%29%3AInt-class-method" class="signature"><strong>.hamming</strong>(s1 : String, s2 : String) : Int</a>
103+
104+
<div class="summary"><p>Returns the number of substitutions that exist between two strings of equal length.</p></div>
105+
106+
</li>
107+
108+
<li class="entry-summary">
109+
<a href="#jaro%28s1%3AString%2Cs2%3AString%29-class-method" class="signature"><strong>.jaro</strong>(s1 : String, s2 : String)</a>
110+
111+
<div class="summary"><p>A measure of similarity between two strings based on matching characters.</p></div>
112+
113+
</li>
114+
115+
<li class="entry-summary">
116+
<a href="#jaro_winkler%28s1%3AString%2Cs2%3AString%2Cscaling_factor%3D0.1%29-class-method" class="signature"><strong>.jaro_winkler</strong>(s1 : String, s2 : String, scaling_factor = <span class="n">0.1</span>)</a>
117+
118+
<div class="summary"><p>Similar to regular Jaro, but gives a higher score for matching from the beginning of the string.</p></div>
119+
120+
</li>
121+
122+
<li class="entry-summary">
123+
<a href="#levenshtein%28s1%3AString%2Cs2%3AString%29%3AInt-class-method" class="signature"><strong>.levenshtein</strong>(s1 : String, s2 : String) : Int</a>
124+
125+
<div class="summary"><p>Returns the min edit distance between two strings.</p></div>
126+
127+
</li>
128+
129+
</ul>
130+
131+
132+
133+
134+
135+
136+
137+
<div class="methods-inherited">
138+
139+
</div>
140+
141+
142+
143+
144+
<h2>Class Method Detail</h2>
145+
146+
<div class="entry-detail" id="damerau_levenshtein(s1:String,s2:String):Int-class-method">
147+
<div class="signature">
148+
149+
def self.<strong>damerau_levenshtein</strong>(s1 : String, s2 : String) : Int
150+
151+
<a class="method-permalink" href="#damerau_levenshtein%28s1%3AString%2Cs2%3AString%29%3AInt-class-method">#</a>
152+
</div>
153+
154+
<div class="doc"><p>A variation of the Levenshtein distance, this counts transpositions as a single edit.</p>
155+
156+
<pre><code><span class="t">StringMetrics</span>.damerau_levenshtein(<span class="s">&quot;char&quot;</span>, <span class="s">&quot;hcar&quot;</span>) <span class="o">==</span> <span class="n">1</span></code></pre>
157+
158+
<p>as opposed to a distance of 2 from levenshtein on it's own</p>
159+
160+
<p>Ported from <a href="https://github.com/jamesturk/jellyfish/blob/master/jellyfish/_jellyfish.py" target="_blank">here</a></p></div>
161+
162+
<br/>
163+
<div>
164+
165+
[<a href="https://github.com/mlobl/string-metrics/blob/cd482346d54b593f0e62779e4d9fa8b3c1386a8b/src/string-metrics.cr#L59" target="_blank">View source</a>]
166+
167+
</div>
168+
</div>
169+
170+
<div class="entry-detail" id="hamming(s1:String,s2:String):Int-class-method">
171+
<div class="signature">
172+
173+
def self.<strong>hamming</strong>(s1 : String, s2 : String) : Int
174+
175+
<a class="method-permalink" href="#hamming%28s1%3AString%2Cs2%3AString%29%3AInt-class-method">#</a>
176+
</div>
177+
178+
<div class="doc"><p>Returns the number of substitutions that exist between two strings of equal length.
179+
Will raise an ArgumentError if both parameters aren't of the same length </p>
180+
181+
<pre><code class='language-crystal'><span class="t">StringMetrics</span>.hamming(<span class="s">&quot;Micro&quot;</span>, <span class="s">&quot;Macro&quot;</span>) <span class="o">==</span> <span class="n">1</span></code></pre></div>
182+
183+
<br/>
184+
<div>
185+
186+
[<a href="https://github.com/mlobl/string-metrics/blob/cd482346d54b593f0e62779e4d9fa8b3c1386a8b/src/string-metrics.cr#L47" target="_blank">View source</a>]
187+
188+
</div>
189+
</div>
190+
191+
<div class="entry-detail" id="jaro(s1:String,s2:String)-class-method">
192+
<div class="signature">
193+
194+
def self.<strong>jaro</strong>(s1 : String, s2 : String)
195+
196+
<a class="method-permalink" href="#jaro%28s1%3AString%2Cs2%3AString%29-class-method">#</a>
197+
</div>
198+
199+
<div class="doc"><p>A measure of similarity between two strings based on matching characters.
200+
Returns 0 if there is no similarity while 1 is an exact match</p>
201+
202+
<pre><code class='language-crystal'> <span class="t">StringMetrics</span>.jaro(<span class="s">&quot;MARTHA&quot;</span>, <span class="s">&quot;MARHTA&quot;</span>).round(<span class="n">2</span>) <span class="o">==</span> <span class="n">0.94</span></code></pre></div>
203+
204+
<br/>
205+
<div>
206+
207+
[<a href="https://github.com/mlobl/string-metrics/blob/cd482346d54b593f0e62779e4d9fa8b3c1386a8b/src/string-metrics.cr#L169" target="_blank">View source</a>]
208+
209+
</div>
210+
</div>
211+
212+
<div class="entry-detail" id="jaro_winkler(s1:String,s2:String,scaling_factor=0.1)-class-method">
213+
<div class="signature">
214+
215+
def self.<strong>jaro_winkler</strong>(s1 : String, s2 : String, scaling_factor = <span class="n">0.1</span>)
216+
217+
<a class="method-permalink" href="#jaro_winkler%28s1%3AString%2Cs2%3AString%2Cscaling_factor%3D0.1%29-class-method">#</a>
218+
</div>
219+
220+
<div class="doc"><p>Similar to regular Jaro, but gives a higher score for matching from the beginning
221+
of the string. Only change the scaling factor if you're intimate with the algorithm.</p>
222+
223+
<pre><code class='language-crystal'><span class="t">StringMetrics</span>.jaro_winkler(<span class="s">&quot;MARTHA&quot;</span>, <span class="s">&quot;MARHTA&quot;</span>).round(<span class="n">2</span>) <span class="o">==</span> <span class="n">0.96</span></code></pre></div>
224+
225+
<br/>
226+
<div>
227+
228+
[<a href="https://github.com/mlobl/string-metrics/blob/cd482346d54b593f0e62779e4d9fa8b3c1386a8b/src/string-metrics.cr#L178" target="_blank">View source</a>]
229+
230+
</div>
231+
</div>
232+
233+
<div class="entry-detail" id="levenshtein(s1:String,s2:String):Int-class-method">
234+
<div class="signature">
235+
236+
def self.<strong>levenshtein</strong>(s1 : String, s2 : String) : Int
237+
238+
<a class="method-permalink" href="#levenshtein%28s1%3AString%2Cs2%3AString%29%3AInt-class-method">#</a>
239+
</div>
240+
241+
<div class="doc"><p>Returns the min edit distance between two strings. If the strings are exactly the same it will return 0,
242+
but if they differ it will return the minimum number of insertions, deletions, or substitutions to make them exactly the same.</p>
243+
244+
<pre><code class='language-crystal'><span class="t">StringMetrics</span>.levenshtein(<span class="s">&quot;Car&quot;</span>, <span class="s">&quot;Char&quot;</span>) <span class="o">==</span> <span class="n">1</span></code></pre>
245+
246+
<p>More detail can be found <a href="https://en.wikipedia.org/wiki/Levenshtein_distance" target="_blank">here</a>.</p>
247+
248+
<p>Ported from <a href="https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Python" target="_blank">here</a></p></div>
249+
250+
<br/>
251+
<div>
252+
253+
[<a href="https://github.com/mlobl/string-metrics/blob/cd482346d54b593f0e62779e4d9fa8b3c1386a8b/src/string-metrics.cr#L13" target="_blank">View source</a>]
254+
255+
</div>
256+
</div>
257+
258+
259+
260+
261+
262+
263+
264+
</div>
265+
266+
</body>
267+
</html>

0 commit comments

Comments
 (0)