Skip to content

Commit ca2e048

Browse files
committed
MsConceptGraph updates
1 parent d8c8802 commit ca2e048

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

examples/concept.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "vendor/autoload.php";
44

5-
$concept = new \Web64\Nlp\MsConcept;
5+
$concept = new \Web64\Nlp\MsConceptGraph;
66
$concept->debug = true;
77

88
$res = $concept->get('php');
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
/**
66
* Microsoft Concept Graph For Short Text Understanding
77
* - Documentation: https://concept.research.microsoft.com/
8-
* - Example: https://concept.research.microsoft.com/api/Concept/ScoreByProb?instance=catalonia&topK=10&smooth=1
8+
* - Example: https://concept.research.microsoft.com/api/Concept/ScoreByProb?instance=laravel&topK=10&smooth=1
99
*/
10-
class MsConcept
10+
class MsConceptGraph
1111
{
1212
private $api_url = "https://concept.research.microsoft.com/api/Concept/";
1313
private $limit = 10;
14-
private $smooth = 0.0004;
14+
private $smooth = 0.0001;
1515
private $score_by = 'ScoreByProb';
1616
public $debug = false;
1717

@@ -34,14 +34,18 @@ public function smooth( $smooth )
3434
return $this;
3535
}
3636

37-
// , $num_results = 10, $score_method = 'ScoreByProb', $smooth = 0.0001
3837
public function get( $word )
3938
{
4039
$url = $this->api_url . $this->score_by . "?instance=" . urlencode($word) . "&topK=". $this->limit . "&smooth=". $this->smooth;
4140

4241
return $this->call( $url );
4342
}
4443

44+
public function getNpmi( $word )
45+
{
46+
return $this->scoreBy('ScoreByNPMI')->get( $url );
47+
}
48+
4549
public function call( $url )
4650
{
4751
if ( $this->debug ) echo "URL: $url \n";

tests/Unit/ConceptTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ConceptTest extends TestCase
99
/** @test */
1010
public function get_concepts_for_words()
1111
{
12-
$concept = new \Web64\Nlp\MsConcept;
12+
$concept = new \Web64\Nlp\MsConceptGraph;
1313
$res = $concept->get('php');
1414

1515
$this->assertNotEmpty( $res );
@@ -21,7 +21,7 @@ public function get_concepts_for_words()
2121
/** @test */
2222
public function score_by_npmi()
2323
{
24-
$concept = new \Web64\Nlp\MsConcept;
24+
$concept = new \Web64\Nlp\MsConceptGraph;
2525
$res = $concept->limit(3)->scoreBy('ScoreByNPMI')->smooth(0.0001)->get('php');
2626

2727
$this->assertNotEmpty( $res );

0 commit comments

Comments
 (0)