Difference: HfstPalindromesScript (1 vs. 3)

Revision 32016-05-18 - KristerLinden

Line: 1 to 1
 
META TOPICPARENT name="HfstAllPages"

HFST: Palindromes Script

Line: 47 to 47
 --> -- ErikAxelson - 2011-09-21

META TOPICMOVED by="eaxelson" date="1358345780" from="KitWiki.HfstPalindromsScript" to="KitWiki.HfstPalindromesScript"
Added:
>
>
META PREFERENCE name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" type="Set" value="FinCLARIN.ViewFinClarinWideEngTemplate"

Revision 22013-01-16 - ErikAxelson

Line: 1 to 1
 
META TOPICPARENT name="HfstAllPages"
Changed:
<
<

HFST: Palindroms Script

>
>

HFST: Palindromes Script

 
Changed:
<
<
See HfstPalindroms for more information.
>
>
See HfstPalindromes for more information.
 
# We assume that /usr/dict/words, a 23K English
Line: 31 to 31
  hfst-fst2strings BidirEnglish | hfst-strings2fst -f $FORMAT > BidirPaths hfst-reverse BidirPaths > BidirPathsReversed
Changed:
<
<
hfst-conjunct BidirPaths BidirPathsReversed > Palindroms
>
>
hfst-conjunct BidirPaths BidirPathsReversed > Palindromes
 
Changed:
<
<
# We finally print all palindroms. Empty conjunctions are printed as empty strings so we only need to
>
>
# We finally print all palindromes. Empty conjunctions are printed as empty strings so we only need to
 # filter out the lines that separate strings coming from separate transducers, # i.e. lines --.
Changed:
<
<
hfst-fst2strings Palindroms | grep -v "\-\-"
>
>
hfst-fst2strings Palindromes | grep -v "\-\-"
 
Line: 45 to 45
 
<--  
-->
-- ErikAxelson - 2011-09-21
Added:
>
>
META TOPICMOVED by="eaxelson" date="1358345780" from="KitWiki.HfstPalindromsScript" to="KitWiki.HfstPalindromesScript"

Revision 12011-09-21 - ErikAxelson

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="HfstAllPages"

HFST: Palindroms Script

See HfstPalindroms for more information.

# We assume that /usr/dict/words, a 23K English
# word list, is available on the machine.

# We first construct BidirEnglish that
# contains all the words whose reverse is also a word of English,
# for example, "madam" and "dog". We wish to keep "madam" (reversed "madam") and
# eliminate "dog" (reversed "god").

cat /usr/dict/words | hfst-strings2fst -f $FORMAT -j > English

# We intersect English with its reverse. We only take into account
# words that contain at least two characters. (Words like "a"
# and "I" are not interesting here.)

echo '[? ?+]' | hfst-regexp2fst -f $FORMAT > MinTwoChars
hfst-reverse English | hfst-conjunct English | hfst-conjunct MinTwoChars > BidirEnglish

# Next we print all strings recognized by =BidirPaths= and construct a stream
# of transducers where each transducer contains one string recognized
# by =BidirPaths=. Then we create a corresponding stream of reversed transducers and
# conjunct the streams. The resulting stream will contain transducers that
# represent a palindrom (e.g. "madam") and empty transducers (e.g. the transducers
# resulting from the intersection of "dog" and "god" and vice versa).

hfst-fst2strings BidirEnglish | hfst-strings2fst -f $FORMAT > BidirPaths
hfst-reverse BidirPaths > BidirPathsReversed
hfst-conjunct BidirPaths BidirPathsReversed > Palindroms

# We finally print all palindroms. Empty conjunctions are printed as empty strings so we only need to
# filter out the lines that separate strings coming from separate transducers,
# i.e. lines =--=.

hfst-fst2strings Palindroms | grep -v "\-\-"


<--  
-->
-- ErikAxelson - 2011-09-21
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback