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 503a589

Browse files
committed
first commit
0 parents commit 503a589

18 files changed

+740
-0
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/*

‎LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Web64
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "web64/php-nlp-client",
3+
"description": "Library for accessing NLP apis",
4+
"keywords": ["nlp", "natural language", "entity extraction", "article extraction", "language detection"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Olav Hjertaker",
9+
"email": "olav.hjertaker@gmail.com"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.6.0"
14+
},
15+
"autoload": {
16+
"psr-4": {
17+
"Web64\\Nlp\\": "src/"
18+
}
19+
},
20+
"autoload-dev": {
21+
"psr-4": {
22+
"Tests\\": "tests/"
23+
},
24+
"files":["tests/utilities/functions.php"]
25+
},
26+
"minimum-stability": "stable"
27+
}

‎composer.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/embeddings.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require "vendor/autoload.php";
4+
5+
$nlpserver_config = [
6+
'hosts' => [
7+
'http://localhost:6400/',
8+
'http://localhost:6400/',
9+
],
10+
'debug' => true,
11+
];
12+
13+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
14+
15+
$neighbours = $nlp->embeddings('obama', 'no');
16+
17+
print_r( $neighbours );

‎examples/language_detection.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require "vendor/autoload.php";
4+
5+
$nlpserver_config = [
6+
'hosts' => [
7+
'http://localhost:6400/',
8+
'http://localhost:6400/',
9+
],
10+
'debug' => false,
11+
];
12+
13+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
14+
15+
$texts = [
16+
'en' => "The quick brown fox jumps over the lazy dog",
17+
'pt' => "Tirar o cavalinho da chuva.",
18+
'no' => "Det er vanskelig å spå – især om fremtiden",
19+
'da' => "Så er den ged barberet",
20+
'sv' => "Släng dig i väggen",
21+
'ca' => "Salut i força al canut",
22+
];
23+
24+
foreach( $texts as $lang => $text)
25+
{
26+
echo "\nTEXT: $text\n";
27+
$detected_language = $nlp->language( $text );
28+
echo " -> detected language: {$detected_language} - [actual: {$lang}]\n";
29+
30+
}

‎examples/newspaper.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require "vendor/autoload.php";
4+
5+
$nlpserver_config = [
6+
'hosts' => [
7+
'http://localhost:6400/',
8+
'http://localhost:6400/',
9+
],
10+
'debug' => true,
11+
];
12+
13+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
14+
15+
$newspaper = $nlp->newspaperUrl('http://www.bbc.com/news/science-environment-43710766');
16+
17+
print_r( $newspaper );

‎examples/polyglot.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
require "../vendor/autoload.php";
3+
4+
$nlpserver_config = [
5+
'hosts' => [
6+
'http://localhost:6400/',
7+
'http://localhost:6400/',
8+
],
9+
'debug' => false,
10+
];
11+
12+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
13+
14+
15+
$text = "Den har en tykk, sukkulent stamme som blir 1,5–8 m høy. Stammen er bare forgrenet i toppen på eldre planter. Stammen og eventuelle greiner er dekket av lange torner, som er omdannede akselblad. I toppen av planten sitter en rosett med avlange blad. Bladene er olivengrønne på oversiden og lyse under. Etterhvert som planten vokser, faller bladene av nedover stammen, men tornene står parvis igjen i de gamle bladfestene. Blomstene er femtallige og hvite. Arten vokser i torneskogene på sørlige og sørvestlige Madagaskar opptil 750 moh.
16+
Madagaskarpalme blir plantet i hager i områder uten frost, og i kaldere strøk er den en populær stueplante. Til tross for navnet er den ingen palme, og den er heller ingen kaktus. Den utvikler sjelden blomster når den dyrkes innendørs. Planten mister bladene når den gjør seg klar til tørketiden. Da må den ikke vannes, ellers råtner stammen innenfra og planten dør.";
17+
18+
19+
$text = "Barack Hussein Obama II is an American politician who served as the 44th President of the United States from 2009 to 2017. The first African American to assume the presidency, he was previously the junior United States Senator from Illinois from 2005 to 2008. Before that, he served in the Illinois State Senate from 1997 until 2004.
20+
Obama was born in 1961 in Honolulu, Hawaii, two years after the territory was admitted to the Union as the 50th state. Raised largely in Hawaii, Obama also spent one year of his childhood in Washington State and four years in Indonesia. After graduating from Columbia University in New York City in 1983, he worked as a community organizer in Chicago. In 1988 Obama enrolled in Harvard Law School, where he was the first black president of the Harvard Law Review. After graduation, he became a civil rights attorney and professor and taught constitutional law at the University of Chicago Law School from 1992 to 2004. Obama represented the 13th District for three terms in the Illinois Senate from 1997 to 2004, when he ran for the U.S. Senate. Obama received national attention in 2004 with his unexpected March primary win, his well-received July Democratic National Convention keynote address, and his landslide November election to the Senate. In 2008, Obama was nominated for president a year after his campaign began and after a close primary campaign against Hillary Clinton. He was elected over Republican John McCain and was inaugurated on January 20, 2009. Nine months later, Obama was named the 2009 Nobel Peace Prize laureate, accepting the award with the caveat that he felt there were others 'far more deserving of this honor than I.'
21+
During his first two years in office, Obama signed many landmark bills into law. The main reforms were the Patient Protection and Affordable Care Act (often referred to as 'Obamacare', shortened as the 'Affordable Care Act'), the Dodd–Frank Wall Street Reform and Consumer Protection Act, and the Don't Ask, Don't Tell Repeal Act of 2010. The American Recovery and Reinvestment Act of 2009 and Tax Relief, Unemployment Insurance Reauthorization, and Job Creation Act of 2010 served as economic stimulus amidst the Great Recession. After a lengthy debate over the national debt limit, Obama signed the Budget Control and the American Taxpayer Relief Acts. In foreign policy, Obama increased U.S. troop levels in Afghanistan, reduced nuclear weapons with the United States–Russia New START treaty, and ended military involvement in the Iraq War. He ordered military involvement in Libya in opposition to Muammar Gaddafi; Gaddafi was killed by NATO-assisted forces, and he also ordered the military operation that resulted in the death of Osama bin Laden.
22+
After winning re-election by defeating Republican opponent Mitt Romney, Obama was sworn in for a second term in 2013. During his second term, Obama promoted inclusiveness for LGBT Americans. His administration filed briefs that urged the Supreme Court to strike down same-sex marriage bans as unconstitutional (United States v. Windsor and Obergefell v. Hodges). Obama advocated for gun control in response to the Sandy Hook Elementary School shooting, and issued wide-ranging executive actions concerning climate change and immigration. In foreign policy, Obama ordered military intervention in Iraq in response to gains made by ISIL after the 2011 withdrawal from Iraq, continued the process of ending U.S. combat operations in Afghanistan, promoted discussions that led to the 2015 Paris Agreement on global climate change, initiated sanctions against Russia following the invasion in Ukraine and again after Russian interference in the 2016 United States elections, brokered a nuclear deal with Iran, and normalized U.S. relations with Cuba. Obama left office in January 2017 with a 60% approval rating and currently resides in Washington, D.C. Since leaving office, his presidency has been favorably ranked by historians and the American general public.[2][3]";
23+
24+
25+
$text = "– Norsk matvarebransje er preget av for dyre varer, for lite utvalg, for lite konkurranse og for lite åpenhet, slo Isaksen fast på et debattmøte for matvarebransjen mandag, der representanter for dagligvarebransjen, organisasjoner og offentlige myndigheter var samlet for å diskutere konkurranseforholdene.
26+
Gal retning.
27+
– Regjeringen er bekymret for konkurransen, både blant dagligvarekjedene og blant leverandørene. Vi har fått dyrere mat og dårligere utvalg. Utviklingen har gått i gal retning, slår Røe Isaksen fast.
28+
Nå er næringsministeren på jakt etter tiltak som kan bedre situasjonen og dempe markedsmakten til matvaregigantene. Men han er samtidig klar på at det ikke finnes noen «quick fix».
29+
– Dette er en komplisert analyse, som ikke har ett enkelt svar. Det er for tidlig å si noe om hvilke tiltak vi vil gjennomføre. Men jeg sier veldig klart og tydelig at denne regjeringen er villig til å sette i verk tiltak for å gjøre konkurransesituasjonen bedre, sier statsråden, som nå vil be fagmiljøer om å utrede saken.
30+
Når en utredning vil være klar, eller når regjeringen kan tenkes å komme med forslag til tiltak, er altfor tidlig å si, sier Røe Isaksen til NTB.
31+
– Jeg ønsker å gjøre noe med denne saken. Men det må jo være noe som virker, sier han.
32+
Prisregulering.
33+
Ett tema som har vært på dagsordenen den siste tiden, er om store leverandører som Orkla og Tine skal tvinges til å gi alle butikkjeder samme pris på varene. I dag kan for eksempel giganten Norgesgruppen, som blant annet kontrollerer kjedene Meny og Kiwi, forhandle seg fram til langt bedre priser enn Rema 1000.
34+
Slike innkjøpsbetingelser hindrer også nye aktører til å komme inn på markedet, viser en fersk rapport fra Oslo Economics.
35+
Situasjonen blir heller ikke bedre av at Norgesgruppen også eier det største distribusjonsselskapet, Asko.";
36+
37+
$detected_lang = $nlp->language( $text );
38+
$polyglot = $nlp->polyglot( $text, $detected_lang );
39+
40+
print_r($polyglot);
41+
42+
echo "\nSentiment:\n";
43+
print_r( $polyglot->getSentiment() );
44+
45+
46+
47+
echo "\n\nEntities:\n";
48+
print_r( $polyglot->getEntities() );
49+
50+
51+
echo "\n\nEntity Types:\n";
52+
print_r( $polyglot->getEntityTypes() );

‎phpunit.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
<testsuites>
12+
<testsuite name="Feature">
13+
<directory suffix="Test.php">./tests/Feature</directory>
14+
</testsuite>
15+
16+
<testsuite name="Unit">
17+
<directory suffix="Test.php">./tests/Unit</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist processUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">./app</directory>
23+
</whitelist>
24+
</filter>
25+
<php>
26+
<env name="APP_ENV" value="testing"/>
27+
</php>
28+
</phpunit>

‎src/Classes/EntityClean.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Web64\Client\Classes\EntityClean;
4+
5+
class EntityClean
6+
{
7+
protected $entity;
8+
9+
public function handle( $entity )
10+
{
11+
$this->entity = $entity;
12+
13+
14+
return $this->entity;
15+
}
16+
17+
18+
}

0 commit comments

Comments
(0)

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