I have a string and I change it into an array like this:
$a = "adik melempar kail ke tengah danau"
Array :
[0] => adik
[1] => melempar
[2] => kail
[3] => ke
[4] => tengah
[5] => danau
I have marked array[1] => melempar
as verb (kata kerja).
How do I mark the next array (after array[1]
) as object and the previous array (before array[1]
) as subject?
An english example might be:
$a = "brother throw hook to the lake"
Array :
[0] => brother
[1] => throw
[2] => hook
[3] => to
[4] => the
[5] => lake
Are you going to loop through the array looking for verbs? Assuming you have an array index variable $index, you could generally do something like this:
$words = explode(" ", $theSentence);
$index = 0;
foreach($words as $key=$theWord){
// apply your logic here that determines whether word is a verb
if isVerb($theWord){
$arrayResult[$index] = "verb";
if($index > 0){
$arrayResult[$index - 1 ] = 'subject';
arrayResult[$index + 1 ] = 'object';
}
}
}
...
This is all very general, of course, since I don't know the context. You seem to have some logic in mind to determine what the words on either side of the verb are.