Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad0716f

Browse files
committed
summarize test
1 parent da2fb54 commit ad0716f

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

‎README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
This is a simple PHP library for performing Natural Language tasks using Web64's NLP-Server https://github.com/web64/nlpserver.
44

55
NLP Tasks Available through Web64's NLP Server:
6-
* Language detection
6+
* [Language detection](#language-detection)
77
* Entity Extraction (NER) - Multilingual
88
* Sentiment Analysis - Multilingual
99
* Embeddings / Neighbouring words - Multilingual
10-
* Article Extraction from HTML or URL
10+
* [Article Extraction from HTML or URL](#article--metadata-extraction)
1111
* Summarization
1212

1313
NLP Tasks Available through Stanford's CoreNLP Server:
@@ -80,7 +80,7 @@ Array
8080
```
8181

8282

83-
### Polyglot Entities & Sentiment Analysis
83+
### Entitiy Extraction & Sentiment Analysis (Polyglot)
8484
This uses the Polyglot multilingual NLP library to return entities and a sentiment score for given text.Ensure the models for the required languages are downloaded for Polyglot.
8585

8686
```php
@@ -112,7 +112,7 @@ $polyglot->getPersons(); // Array of people
112112

113113
$polyglot->getEntities();
114114
/*
115-
Returns combined array of all entities
115+
Returns flat array of all entities
116116
Array
117117
(
118118
[0] => Ben
@@ -157,7 +157,7 @@ Array
157157
*/
158158
```
159159

160-
English is used by default. To use another languageensure Spacy language model is downloaded and add the language as the second parameter
160+
English is used by default. To use another language, ensure the Spacy language model is downloaded and add the language as the second parameter
161161
```php
162162
$entities = $nlp->spacy_entities( $spanish_text, 'es' );
163163
```

‎tests/Unit/SummarizerTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,40 @@ public function get_summary()
3737

3838
$this->assertNotEmpty( $summary );
3939
}
40+
41+
/** @test */
42+
public function get_summary_word_count()
43+
{
44+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
45+
46+
$text = "Portland stone is a limestone from the Tithonian stage of the Jurassic period quarried on the Isle of Portland, Dorset. The quarries consist of beds of white-grey limestone
47+
separated by chert beds. It has been used extensively as a building stone throughout the British Isles, notably in major public buildings in London such as St Paul's Cathedral and
48+
Buckingham Palace. Portland stone is also exported to many countries—Portland stone is used in the United Nations headquarters building in New York City, for example.
49+
Portland stone formed in a marine environment, on the floor of a shallow, warm, sub-tropical sea probably near land (as evidenced by fossilized driftwood, which is not uncommon).
50+
When seawater is warmed by the sun, its capacity to hold dissolved gas is reduced, consequently dissolved carbon dioxide (CO2) is released into the atmosphere as a gas.
51+
Calcium and bicarbonate ions within the water are then able to combine, to form calcium carbonate (CaCO3) as a precipitate.
52+
The process of lime scale build up in a kettle in hard water areas is similar. Calcium carbonate is the principal constituent of most limestones.
53+
Billions of minute crystals of precipitated calcium carbonate (called calcite) accumulated forming lime mud (called micrite) which covered the sea floor.
54+
Small particles of sand or organic detritus, such as shell fragments, formed a nucleus, which became coated with layers of calcite as they were rolled around in the muddy micrite.
55+
56+
The calcite gradually accumulated (by accretion) around the fragments of shell in concentric layers, forming small balls (of less than 0.5 mm diameter).
57+
This process is similar to the way in which a snowball grows in size as it is rolled around in the snow. Over time, countless billions of these balls, known as \"ooids\" or \"ooliths\"
58+
(from the Greek for \"egg-shaped\" or \"egg-stone\"), became partially cemented together (or lithified) by more calcite, to form the oolitic limestone we now call Portland stone.
59+
Fortunately, the degree of cementation in Portland stone is such that the stone is sufficiently well cemented to allow it to resist weathering, but not so well cemented that it can't be
60+
readily worked (cut and carved) by masons. This is one of the reasons why Portland stone is so favoured as a monumental and architectural stone.
61+
Dr Geoff Townson conducted three years doctoral research on the Portlandian, being the first to describe the patch-reef facies and Dorset-wide sedimentation details .
62+
Dr Ian West of the School of Ocean and Earth Sciences at Southampton University completed a detailed geological survey of Withies Croft Quarry before the Portland Beds were quarried by
63+
Albion Stone plc.
64+
";
65+
66+
$word_count = 40;
67+
$summary = $nlp->summarize( $text, $word_count );
68+
69+
$this->msg( $summary );
70+
$this->msg( "Word Count: ". str_word_count($summary) );
71+
72+
$this->assertNotEmpty( $summary );
73+
$this->assertTrue( str_word_count($summary) <= ($word_count+10) );
74+
$this->assertLessThanOrEqual(($word_count+10), str_word_count($summary));
75+
}
4076
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /