1

would it be appropriate to use PHP's sscanf to read user submitted sentences and try to get data from them? For example:

User inputs:

"James is child of Bill"and I want to make $child="james" and $parent="bill"

or: "Mary is the mother of kate"and I want to make $child="kate" and $parent="mary"

There could be quite a few other possible sentence formats that I would have to extract data from (no more than 100-ish).

So should I use:

$templates = array("%s is a child of %s","%s is the mother of %s");
$i=0;
$max = count($templates);
while( ($test == -1) && (i < $max) ) {
    $test = sscanf($userInput, $templates[i]);
    $i++;
}
if(i < $max) {
    sscanf($userInput, $templates[i],$child,&parent);//hmm, what if $child,&parent should be the other way around?
} else {
    echo "template not found for sentence";
}

? So I'm in a bit of a rut as you can see, can anyone suggest a better way of doing it, or a way to get this solution working?

Really appreciate it!

1 Answers1

0

Welcome to the area of Graph Theory. I don't think you can solve your problem with sentence templates. Luckily a similar subject has been discussed here on SO. See this topic for that discussion How to Model Real-World Relationships in a Graph Database (like Neo4j)?

Community
  • 1
  • 1
  • Thanks Parahat, not what I asked for, but wow! Graph theory is really interesting. –  Jul 01 '12 at 07:33