The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 20, 2019, 11:40:14 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: insert keywords using php  (Read 3270 times)
jaobedoza
Rookie
**
Offline Offline

Posts: 11


View Profile
« on: January 31, 2009, 11:42:27 PM »

i have this idea of using mygen as a doorway page generator. i want to use the markov class and be able to randomly insert the keywords on the generated markov articles, and also be able to control how many times this keyword is inserted so i can tweak the keyword density of the generated pages.

but i cant seem to find a php function to do this. is there a simple "string_insert" function in php that can handle this?

thanks,

jay

 
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: February 01, 2009, 12:28:31 PM »

There's nothing quite so "all in" as string_insert, you'll need to be a bit more creative than that.

Probably the most traditional way is to split a string then recombine it with your new value ie.,

$foo = 'The quick brown fox jumped the lazy dog';
$bar = 'over';
$left = substr(0, 15, $foo);
$right = substr(15, strlen($foo), $foo);
$newStr = $left . $bar . $right;
// newStr now = The quick brown fox fox jumped over the lazy dog

This however will take WAY long and be code intensive (at best) for you to do.

You might consider taking your content and splitting it on spaces into an array thus:
$words = explode(' ', $foo);

then using array_splice() to insert keywords where you want into the array - imaging it now "vertically" rather than "horizontally" sequential, the putting it back together in one fell swoop:

$newStr = implode(' '), $words)

There are only about 19 bazillion ways to do similar things, this is just one. Perhaps others will chime in with other techniques.

You can find the params for array_splice here: http://us2.php.net/manual/en/function.array-splice.php
« Last Edit: February 01, 2009, 12:30:02 PM by perkiset » Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #2 on: February 02, 2009, 11:09:00 AM »

Replace random nouns with your keyword.

That is, if your markov algorithm is part-of-speech aware. Mine is, but I have not shared it yet. I probably will wind up sharing it once I have the kinks worked out, being all about open source and all.
Logged

hai
jaobedoza
Rookie
**
Offline Offline

Posts: 11


View Profile
« Reply #3 on: February 02, 2009, 05:28:02 PM »

i tried converting the content into an array and merging/splicing it with another array containing my keywords. i can't quite get the results i want. still playing with it.

Quote
Replace random nouns with your keyword.

That is, if your markov algorithm is part-of-speech aware. Mine is, but I have not shared it yet. I probably will wind up sharing it once I have the kinks worked out, being all about open source and all.


unfortunately i'm only using the very basic markov class in mygen. it will be great if you can share that content gen of yours.
Logged

No links in signatures please
oldenstylehats
Rookie
**
Offline Offline

Posts: 19


View Profile
« Reply #4 on: February 05, 2009, 11:50:42 PM »

Replace random nouns with your keyword.

That is, if your markov algorithm is part-of-speech aware. Mine is, but I have not shared it yet. I probably will wind up sharing it once I have the kinks worked out, being all about open source and all.
I'd also love to see this.
Logged

No links in signatures please
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #5 on: February 06, 2009, 07:15:31 AM »

It's a real plodder. Lousy performance because it uses database lookups to determine a word's part of speech. I am working on a faster solution.
Logged

hai
jaobedoza
Rookie
**
Offline Offline

Posts: 11


View Profile
« Reply #6 on: February 06, 2009, 08:13:52 PM »

instead of processing the content as an array, how can i insert the keyword every, let's say, 80-100 words. 
Logged

No links in signatures please
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #7 on: February 07, 2009, 05:19:45 AM »

Replace random nouns with your keyword.

That is, if your markov algorithm is part-of-speech aware. Mine is, but I have not shared it yet. I probably will wind up sharing it once I have the kinks worked out, being all about open source and all.

Is this based on WordNET VS? I've been working on something like this for a while on and off, but I've never had the patience to finish the exercise.

DM
Logged
mampy
Journeyman
***
Offline Offline

Posts: 68


View Profile
« Reply #8 on: February 07, 2009, 10:55:55 AM »

Quote
replace random nouns with keyword.

I had a legacy system like this in notebook form called mad libs when i was a kid...

lol...  So you have a sentence 'diagrammer' dealie?  please expound..

<update>
I guess what im asking is how are you using this and why are you
trying to be part of speech aware.

(leans in with acute interest...)

</update>
« Last Edit: February 08, 2009, 05:20:33 PM by mampy » Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #9 on: February 09, 2009, 09:03:42 AM »

DM: Yes, wordnet right now.

mampy: Mostly, my cursory interest came about due to conversations with Fantomaster on generating real content that passes a human inspection. It's still just cursory. I've found that the quality of your content doesn't really matter if it's not for users.
Logged

hai
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!