Just pick a reasonable value to test $ratio against (like maybe 1.0):

#!/usr/bin/perl # http://perlmonks.org/?node_id=1174957 use strict; use warnings; use Algorithm::Diff qw(traverse_sequences); my $template = <<END; The earliest conceptualization of human rights is credited to ideas ab +out natural rights emanating from natural law. In particular, the iss +ue of universal rights was introduced by the examination of extending + rights to indigenous peoples by Spanish clerics, such as Francisco d +e Vitoria and Bartolomé de Las Casas. In the Valladolid debate, Juan +Ginés de Sepúlveda, who maintained an Aristotelian view of humanity a +s divided into classes of different worth, argued with Las Casas, who + argued in favour of equal rights to freedom from slavery for all hum +ans regardless of race or religion. END my $copywitherrors = <<END; The earliest conceptulization of human rights is credited to ideas abo +ut rights emanating from natural law. In particular the issue of univ +ersal rights was introduced by extending rights to indigenous peoples + by Spanish clerics, such as Francisco de Vitoria and Bartolomé de La +s Casas. In the Valladolid debate, Juan Ginés de Sepúlveda, who maint +ained an Aristotelian view of humanity as divided into clases of diff +erent worth argued with Las Casas, who argued in favour of equal righ +ts to freedom from slavery for all humans regardless of race. END my $somethingelse = <<END; Although ideas of rights and liberty have existed in some form for muc +h of human history, there is agreement that the earlier conceptions d +o not closely resemble the modern conceptions of human rights. Accord +ing to Jack Donnelly, in the ancient world, "traditional societies ty +pically have had elaborate systems of duties... conceptions of justic +e, political legitimacy, and human flourishing that sought to realize + human dignity, flourishing, or well-being entirely independent of hu +man rights. These institutions and practices are alternative to, rath +er than different formulations of, human rights".14 The history of hu +man rights can be traced to past documents, particularly Constitution + of Medina (622), Al-Risalah al-Huquq (659-713), Magna Carta (1215), +the Twelve Articles of Memmingen (1525), the English Bill of Rights ( +1689), the French Declaration of the Rights of Man and of the Citizen + (1789), and the Bill of Rights in the United States Constitution (17 +91) END sub compare { my ($old, $new) = @_; my $changes = 0; traverse_sequences( [ split //, $old ], [ split //, $new ], { DISCARD_A => sub { $changes++ }, DISCARD_B => sub { $changes++ }, } ); return $changes; }; my $length = length $template; print "length: $length\n"; my $answer = compare($template, $copywitherrors); my $ratio = $answer / $length; printf "copywitherrors: %d ratio %.3f\n", $answer, $ratio; $answer = compare($template, $somethingelse); $ratio = $answer / $length; printf "somethingelse: %d ratio %.3f\n", $answer, $ratio;

In reply to Re: comparing sentences by tybalt89
in thread comparing sentences by cntrtrst

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.