Analysing usermodelling data returned from Watson
[
Watson returns usermodelling data in json format.
This is stored in a file testoutput.json.
Example shows how to process that.
]
public function actionprofileanalyse() {
$fileName =
'testoutput.json';
$data =
file_get_contents($fileName);
$decodeddata =
json_decode($data, true);
$adventrous =
$decodeddata["tree"]["children"][0]["children"][0]["children"][0]["children"][0];
echo
$adventrous["id"] . "\n";
$adval =
$adventrous["percentage"] * 100;
$advcount = sizeof($decodeddata["tree"]["children"][0]["children"][0]["children"][0]["children"]);
$adv =
$decodeddata["tree"]["children"][0]["children"][0]["children"][0]["children"];
for ($i = 0;
$i < $advcount; $i++) {
print
$adv[$i]["id"];
print
($adv[$i]["percentage"] * 100) . "</br>";
}
$advcount1 =
sizeof($decodeddata["tree"]["children"][0]["children"][0]["children"]);
$adv1 =
$decodeddata["tree"]["children"][0]["children"][0]["children"];
for ($j = 0;
$j < $advcount1; $j++) {
$advcount2
= sizeof($adv1[$j]["children"]);
$adv2 =
$adv1[$j]["children"];
for ($i =
0; $i < $advcount2; $i++) {
print
$adv2[$i]["id"] . "</br>";
print
($adv2[$i]["percentage"] * 100) . "</br>";
}
}
}
No comments:
Post a Comment