I have a list of words and there is a list of the associated part of the speech tag. I use one indexed tube I want to iterate on both (matte index), such as input in a .NET function. Is this the best way (this works, but not natural to me):
tagging model = SeqLabeler.loadModel (lthPath + "model \ penn_00_18_split_dict.model"); Let lemmatizer = new lemmatizer (lthPath + "v_n_a.txt") input = "rain in the span falls on the rain" to the words = preprocessor. TokenizeSentence (input) tags = SeqLabeler.tagSentence (tagging model, word) lemmas = Array .map2 (funny xy -> lemmatizer.lookup (x, y)) The word tag
Your code sounds great to me - most of it relates to some loading and initialization, so you can not do much to simplify that part. Alternatively for Array.map2 , you can add Seq.zip to Seq.map - zip function There are pairs of elements that match the matching ones in one to two views:
let's lemmas = Seq.zip word tags | & Gt; Seq.map (Fun (X, Y) -> LeMmetzer. Lookup (X, Y)) Since the lookup function takes a follower that gives you Given an argument, you can write:
// standard syntax using the pipeline operator lemmas = Seq.zip word tag | & Gt; Seq.map lemmatizer.lookup // An alternative syntax is doing the same thing lemmas = (word, tag) || & Gt; Seq.zip | & Gt; Seq.map lemmatizer.lookup used in the second version > & gt; The operator takes two types of tubals and passes them on the right side of the function as two sides of the argument, which means that (a, b) || & Gt; F means f a b . | & Gt; Operator only takes a single value on the left, so (a, b) | & Gt; F will mean f (a, b) (which will work if the function f instead of the expected tuple, space separately, parameter).
If you need lemmas to end in an array, you will add Array.ofSeq at the end of the processing pipeline (all < Code> Seek function works with sequence, which corresponds to IEnumerable )
Using another option sequence expression (You
let lemmas = [| Seq.zip word tags for wt // wt tuple (string * string) yield lemmatizer.lookup wt |] Whether or not to use sequence expression - this is just a personal Is the priority. In this case the first option seems to be more concise, but sequence expression can be more readable for people familiar with things like partial function applications (in lower version using Seq.map )
Comments
Post a Comment