#!/usr/bin/perl # http://perlmonks.org/?node_id=1129709 use Algorithm::Diff qw(traverse_sequences); use strict; use warnings; my (@old, @new, %dictionary); sub addtodictionary { @old || @new and $dictionary{"@old"}{"@new"}++, @old = @new = (); } while(<DATA>) { my @from = split; my @to = split ' ', <DATA> // 'unmatched line'; traverse_sequences( \@from, \@to, { MATCH => sub {addtodictionary()}, DISCARD_A => sub {push @old, $from[shift()]}, DISCARD_B => sub {push @new, $to[pop()]}, } ); addtodictionary(); } use YAML; print Dump \%dictionary; __DATA__ This apple is colored red. This apple is coloured red. I need to buy a round trip ticket. I need to buy a return ticket. Jack rode the elevator to the top floor. Jack took the lift to the top floor.

produces (note that this mapping *can* be "one to many")

--- colored: coloured: 1 elevator: lift: 1 rode: took: 1 round trip: return: 1

In reply to Re: Comparing strings to extract the different words/expressions by Anonymous Monk
in thread Comparing strings to extract the different words/expressions by TravelAddict

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.