Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have a series of databases with articles in them. These are front-ended by a Wordpress blog interface.

I've been importing the articles into Wordpress with a little spider I wrote that pulls them from a remote article resource. This part all works.

The relevant insert code looks something like this (wrapped for PM):

my $users_sth = $dbh->prepare(qq{ INSERT IGNORE INTO `wp_users` (`user_login` , `user_pass` , `user_nicename` , `user_ +email` , `user_registered` , `user_status` , `display_name` ) VALUES (?, $random_password, ?, 'no-email\@localhost', ?, 0, ? +)}); $users_sth->execute($authors[$i], $authors[$i], $now, $authors[$i]); my $author_sth = $dbh->prepare(qq{SELECT id from wp_users WHERE user_ +login=?}); my $post_author = $authors[$i]; $author_sth->execute($authors[$i]); $author_sth->bind_col(1, \$post_author); my @output = fetch_body($urls[$i]); while ($author_sth->fetch) { my $post_sth = $dbh->prepare(qq{ INSERT IGNORE INTO `wp_posts` (`post_author` , `post_date` , `post_content` , `post_ +title`) VALUES (?, ?, ?, ?)}); $post_sth->execute($post_author, $now, @output, $title +s[$i]); } };

I had to alter some of the default tables in Wordpress to facilitate this by making post_title a VARCHAR(255) and setting it to unique as well as making user_login unique:

ALTER TABLE `wp_posts` ADD UNIQUE (`post_title`);

The inserts work, and so far no issues and no duplicate USERS in the database, but here's where it gets tricky...

When I'm inserting articles, sometimes there are articles which have "similar" titles and very similar content, written by two different people (plagiarism, no-doubt). Here are some examples:

| 597 | 102 | New Home Builders in Houston + + | 595 | 102 | New Home Builders In Houston Texas + + ... | 772 | 136 | Buy to Let Rental Properties + + | 754 | 136 | Buy to Let Rental Property

There are probably more examples, but those are the two that I picked out visually.

I asked the MySQL folks, and they pointed me to Soundex, but it didn't look that easy to implement, and I've heard bad things about the pattern matching.

So I started looking around and found Text::Levenshtein, Text::WagnerFischer, Text::PhraseDistance and String::Approx.

What I'm trying to figure out, is what is the best way to achieve this (preferably at article import time), so I can eliminate the potential for dupes?

An alternate solution is to import the "dupes", and mark them as "Unpublished", so I can manually review them later.

I don't want to add more tables to the db to facilitate this, I need to stay as close to "stock" as possible.

Ideas? Suggestions? Pseudocode?

In reply to Comparing inputs before inserting into MySQL for "sounds-like" similarity by hacker

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (3)
    As of 2018-08-19 00:17 GMT
    Find Nodes?
      Voting Booth?
      Asked to put a square peg in a round hole, I would:

      Results (186 votes). Check out past polls.