-
-
Save jwosty/dc02958a6a90a55a8732 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Endo = EndsWith of string*string| NoEnding of string | |
EndsWith ("a","b") | |
NoEnding "a" | |
let breakEndingO (w:string) ending = if w.EndsWith ending then w.[0..w.Length-ending.Length-1],ending else w,"" | |
let breakEnding (w:string) ending = if w.EndsWith ending then EndsWith (w.[0..w.Length-ending.Length-1],ending) else NoEnding(w) | |
breakEnding "hellooByInch" "ByInch" | |
breakEnding "xInch" "Inch" | |
breakEnding "Inch" "Inch" | |
breakEnding "x" "Inch" | |
// now break ending over a collection of possible endings | |
let breakEndings (w:string) endings = | |
let e = endings |> List.tryFind (fun ending -> w.EndsWith ending) | |
//match e with | Some ending -> EndsWith (w.[0..w.Length-ending.Length-1],ending) | None -> NoEnding w | |
match e with | Some ending -> w.[0..w.Length-ending.Length-1],ending | None -> w,"" | |
breakEndings "xInch" ["Meter";"Inch"] | |
breakEndings "xInch" ["Metre"] | |
let endings = ["Meter";"Inch";"KPA"] | |
type Feature = Fretting|Grinding|Axing | |
let words = ["RadiusMeter";"RadiusInch";"CenterKPA";"InnerWallKPA";"InnerWallInch"] | |
words |> Seq.map (fun w -> breakEndings w endings) |> Seq.groupBy fst | |
words |> Seq.groupBy (fun w -> breakEndings w endings |> fst) | |
let wordsFe = ["RadiusMeter",[Fretting];"RadiusInch",[Fretting];"CenterKPA",[Grinding;Fretting];"InnerWallKPA",[Grinding;Fretting];"InnerWallInch",[Axing]] | |
wordsFe |> Seq.groupBy (fun (w,f) -> breakEndings w endings |> fst) | |
// an hour into this... may make more sense to hand process and check that there was no change |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment