--- a/build/build.sh Thu Oct 20 12:54:07 2016 +0530
+++ b/build/build.sh Thu Oct 20 12:56:24 2016 +0530
@@ -20,7 +20,7 @@
echoblue "---> preparing bo client"
pushd ../server/bo_client
- npm install
+ /usr/local/bin/npm install
./node_modules/.bin/bower install
popd
echoblue "---> preparing bo client done"
@@ -28,14 +28,14 @@
echoblue "---> preparing back"
pushd ../server/src
php composer.phar install
- npm install
+ /usr/local/bin/npm install
./node_modules/.bin/bower install
popd
echoblue "---> preparing back done"
echoblue "---> preparing app-client"
pushd ../cms/app-client
- npm install
+ /usr/local/bin/npm install
./node_modules/.bin/bower install
popd
echoblue "---> preparing app-client done"
@@ -48,8 +48,14 @@
echoblue "---> checking vagrant"
if vagrant status | grep -q "running"; then
echoblue "---> starting vagrant"
+ if [ type workon ]; then
+ workon ansible
+ fi
vagrant up
VAGRANT_STARTED=true
+ if [ type deactivate ]; then
+ deactivate
+ fi
fi
echoblue "---> done"
--- a/build/post_upgrade.sh Thu Oct 20 12:54:07 2016 +0530
+++ b/build/post_upgrade.sh Thu Oct 20 12:56:24 2016 +0530
@@ -3,9 +3,9 @@
if [ -x /usr/local/bin/drush ]; then
echo "Reactivate corpus module"
- /opt/remi/php56/root/usr/bin/php /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal pm-enable -y corpus
+ /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal pm-enable -y corpus
echo "Clear drupal cache"
- /opt/remi/php56/root/usr/bin/php /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal cc all
+ /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal cc all
fi
echo "Restart httpd"
--- a/build/pre_upgrade.sh Thu Oct 20 12:54:07 2016 +0530
+++ b/build/pre_upgrade.sh Thu Oct 20 12:56:24 2016 +0530
@@ -3,5 +3,5 @@
if [ -x /usr/local/bin/drush ]; then
echo "Deactivate corpus module"
- /opt/remi/php56/root/usr/bin/php /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal pm-disable -y corpus
+ /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal pm-disable -y corpus
fi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/build/set-version.sh Thu Oct 20 12:56:24 2016 +0530
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+set -e
+
+function usage() {
+ cat <<EOF
+Usage: $0 "x.y.z"
+ "x.y.z": version number, following the semver convention
+EOF
+}
+
+if [ $# -ne 1 ]; then
+ echo "Bad number of parameters"
+ usage >&2
+ exit 1
+fi
+
+if [[ "$1" == "-h" || "$1" == "--help" ]]; then
+ usage
+ exit 0
+fi
+
+version=$1
+
+echo "Version: ${version}"
+
+[[ "${version}" =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]] || {
+ echo "Bad format for version."
+ usage >&2
+ exit 1
+}
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+green="\x1B[0;32m" # '\e[1;32m' is too bright for white bg.
+blue="\x1B[1;34m"
+endColor="\x1B[0m"
+
+function echoblue() {
+ echo -e "${blue}$1${endColor}"
+}
+
+pushd "$DIR"
+
+pushd ../server/bo_client
+echoblue "Setting bo_client version"
+/usr/local/bin/npm run set-version -- "$version"
+popd
+
+pushd ../server/src
+echoblue "Setting back version"
+sed -i "" -e "s/\([:space:]*\'version\'[[:space:]]*\=\>[[:space:]]*\'\)[\.0-9]*\(\'.*\)/\1${version}\2/" config/version.php
+popd
+
+pushd ../cms
+echoblue "Setting cms version"
+/usr/local/bin/npm run set-version -- "$version"
+popd
+
+pushd ../cms/app-client
+echoblue "Setting app-client version"
+/usr/local/bin/npm run set-version -- "$version"
+popd
+
+echoblue "Version has been changed, please commit and push if necessary."
+
+
+popd
--- a/cms/app-client/package.json Thu Oct 20 12:54:07 2016 +0530
+++ b/cms/app-client/package.json Thu Oct 20 12:56:24 2016 +0530
@@ -1,6 +1,6 @@
{
"name": "app-client",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Small description for app-client goes here",
"private": true,
"directories": {
@@ -15,7 +15,8 @@
"dl-transcripts": "ember dl-fixtures -u http://127.0.0.1:8000/api/v1/documents/ -d mirage/fixtures/transcripts.js -t transcripts -e \"11280.100/crdo-UVE_MOCIKA_SOUND,11280.100/crdo-CFPP2000_11_SOUND,11280.100/crdo-FRA_PK_IV_10_SOUND,11280.100/crdo-FSL-CUC023_SOUND,11280.100/crdo-NEE_KHIAAK_KO_AK_SOUND,11280.100/crdo-ESLO1_ENT_047\" -p 2 -f es6",
"dl-themes": "ember dl-fixtures -u http://127.0.0.1:8000/api/v1/stats/themes/ -d mirage/fixtures/themes.js -t themes -f es6",
"dl-discourses": "ember dl-fixtures -u http://127.0.0.1:8000/api/v1/stats/discourses/ -d mirage/fixtures/discourses.js -t discourses -f es6",
- "prepare-maps": "node lib/scripts/prepare_maps.js"
+ "prepare-maps": "node lib/scripts/prepare_maps.js",
+ "set-version": "bash -c 'sed -i \"\" -e \"s/\\([:space:]*\\\"version\\\"[[:space:]]*\\:[[:space:]]*\\\"\\)[\\.0-9]*\\(\\\".*\\)/\\1${1}\\2/\" package.json' 0"
},
"repository": "",
"engines": {
--- a/cms/package.json Thu Oct 20 12:54:07 2016 +0530
+++ b/cms/package.json Thu Oct 20 12:56:24 2016 +0530
@@ -1,9 +1,10 @@
{
"name": "corpus-cms",
- "version": "0.0.1",
+ "version": "0.0.3",
"description": "drupal module to embed the Ember app \"app-client\"",
"scripts": {
- "build": "npm run build --prefix app-client/ && gulp copy-module"
+ "build": "npm run build --prefix app-client/ && gulp copy-module",
+ "set-version": "bash -c 'sed -i \"\" -e \"s/\\([:space:]*\\\"version\\\"[[:space:]]*\\:[[:space:]]*\\\"\\)[\\.0-9]*\\(\\\".*\\)/\\1${1}\\2/\" package.json' 0"
},
"author": "IRI",
"devDependencies": {
--- a/readme.md Thu Oct 20 12:54:07 2016 +0530
+++ b/readme.md Thu Oct 20 12:56:24 2016 +0530
@@ -1,9 +1,23 @@
# Projet Corpus de la parole
## Prérequis
-- Vagrant
-- Ansible
-- node
+La plateforme de dévelopement visée est MacOS et Linux.
+Les éléments suivant sont des prérequis:
+ - php >= 5.6
+ - Vagrant
+ - Ansible.
+ - node
+
+### php
+
+### node
+
+### Vagrant
+Vagrant est utilisé pour le développement du back-office et la contruction des pacquets RPM.
+
+### Ansible
+Ansible n'est nécessaire que pour lancer l'environement de contruction des RPM.
+Ansible sera soit installé globalement, soit installé dans un environement virtuel. dans ce cas, `virtualenv-wrapper` doit être installé et l'environement virtuel doit avoir le nom `ansible`.
## Lancement VM dev
- `cd /dev`
@@ -22,22 +36,28 @@
## Initialisation env de dev
- `cd /server/bo_client`
- `npm install`
-- `bower install`
+- `./node_modules/.bin/bower install`
- `cd /server/src`
- télécharger composer.phar (https://getcomposer.org/) et le mettre dans le répertoire server/src
- `php composer.phar install`
- `npm install`
-- `bower install`
+- `./node_modules/.bin/bowerbower install`
## Commandes bo_client
- `ember serve`
- `ember build` -> résultat dans `server/bo_client/dist`
+
## Commandes serveur php
- Compilation css/js : `gulp` -> cette commande lance `ember build` de `/server/bo_client`
- `php artisan serve`
## Creation de version
+- mettre à jour le numéro de version. Pour cela lancer le script `build/set-version.sh "x.y.z"`, avec "x.y.z" le numéro de version
+- lancer le script `build/build.sh`. options:
+ - `-d`: build debug
+ - `-p`: build de production
+
- mettre à jour le fichier version `server/src/config/config/version.php`
- mettre à jour le fichier version `cms/app-client/package.json`
- `cd /server/src`
--- a/server/bo_client/package.json Thu Oct 20 12:54:07 2016 +0530
+++ b/server/bo_client/package.json Thu Oct 20 12:56:24 2016 +0530
@@ -1,6 +1,6 @@
{
"name": "bo-client",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Bo client for Corpus Parole",
"private": true,
"directories": {
@@ -11,7 +11,8 @@
"build": "ember build",
"start": "ember server",
"test": "ember test",
- "dl-documents": "ember dl-fixtures -u http://127.0.0.1:8000/api/v1/documents/ -d server/fixtures/documents.js -p 2 -t documents -f require"
+ "dl-documents": "ember dl-fixtures -u http://127.0.0.1:8000/api/v1/documents/ -d server/fixtures/documents.js -p 2 -t documents -f require",
+ "set-version": "bash -c 'sed -i \"\" -e \"s/\\([:space:]*\\\"version\\\"[[:space:]]*\\:[[:space:]]*\\\"\\)[\\.0-9]*\\(\\\".*\\)/\\1${1}\\2/\" package.json' 0"
},
"repository": "",
"engines": {
--- a/server/src/app/Console/Commands/IndexDocuments.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/app/Console/Commands/IndexDocuments.php Thu Oct 20 12:56:24 2016 +0530
@@ -104,7 +104,7 @@
]
],
'date' => [ 'type' => 'date', 'index' => 'not_analyzed'],
- 'geonames_hyerarchy' => [ 'type' => 'string', 'index' => 'not_analyzed'],
+ 'geonames_hierarchy' => [ 'type' => 'string', 'index' => 'not_analyzed'],
'location' => [ 'type' => 'geo_point'],
'creation_date' => ['type' => 'date', 'index' => 'not_analyzed'],
'language' => ['type' => 'string', 'index' => 'not_analyzed'],
--- a/server/src/app/Http/Controllers/Api/DocumentController.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/app/Http/Controllers/Api/DocumentController.php Thu Oct 20 12:56:24 2016 +0530
@@ -31,10 +31,27 @@
$perPage = intval($request->input('perpage', config('corpusparole.documents_per_page')));
$filters = [];
- $languages = $request->input('language', []);
+
+ $languages = CorpusFilterManager::prepareLanguages($request->input('language', []));
if(!empty($languages)) {
- $filters['language'] = CorpusFilterManager::prepareLanguages($languages);
+ $filters['language'] = $languages;
+ }
+
+ $location = CorpusFilterManager::prepareLocation($request->input('location', ''));
+ if(!empty($location)) {
+ $filters['location'] = $location;
}
+
+ $themes = CorpusFilterManager::prepareTheme($request->input('theme', []));
+ if(!empty($themes)) {
+ $filters['themes'] = $themes;
+ }
+
+ $discourses = CorpusFilterManager::prepareDiscourse($request->input('discourse', []));
+ if(!empty($discourses)) {
+ $filters['discourses'] = $discourses;
+ }
+
$sort = $request->input('sort', null);
$paginator = $this->documentRepository->paginate($filters, $perPage, config('corpusparole.pagination_page_param'), null, $sort);
--- a/server/src/app/Libraries/Filters/CorpusFilterManager.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/app/Libraries/Filters/CorpusFilterManager.php Thu Oct 20 12:56:24 2016 +0530
@@ -9,7 +9,7 @@
public static function getLanguageNode($nodeId) {
$node = null;
$currentNodes = [config('corpusparole.languages_treemap'),];
- while(is_null($node) || !empty($currentNodes)) {
+ while(is_null($node) && !empty($currentNodes)) {
$currentNode = array_pop($currentNodes);
foreach($currentNode['children'] as $n) {
if($n['id'] === $nodeId) {
@@ -40,6 +40,9 @@
public static function prepareLanguages($languages) {
+ if(is_null($languages)) {
+ return [];
+ }
$resLanguage = [];
if(is_string($languages)) {
$languages = [ $languages, ];
@@ -71,4 +74,97 @@
];
}
+ public static function prepareLocation($location) {
+ if(empty($location)) {
+ return null;
+ }
+ if(is_array($location)) {
+ $location = $location[0]; //from test above we know ther is at least one element
+ }
+ if(preg_match(config('corpusparole.geonames_url_regexp'), $location, $m)) {
+ $location = $m[1];
+ }
+ // for the moment we do not make this check. Incorrect loaction format will return an empty result
+ /*if(!preg_match('/\d+/', $location)) {
+ return null;
+ }*/
+
+ return $location;
+ }
+
+ /**
+ * Search in geonames_hierarchy (values are bae geonames ids)
+ */
+ public static function getLocationFilterPart($location) {
+ return [
+ 'term' => [ 'geonames_hierarchy' => "$location" ]
+ ];
+ }
+
+ public static function prepareTheme($entities) {
+ if(empty($entities)) {
+ return [];
+ }
+ if(is_string($entities)) {
+ $entities = [$entities,];
+ }
+ return array_reduce($entities, function($res, $e) {
+ if(preg_match(config('corpusparole.bnf_ark_url_regexp'), $e, $m)) {
+ array_push($res, $m[1]);
+ } elseif(Utils::startsWith($e, config('corpusparole.bnf_ark_id_base'))) {
+ array_push($res, $e);
+ }
+
+ return $res;
+ }, []);
+ }
+
+ public static function getThemeFilterPart($themes) {
+ $nestedQueries = [];
+ foreach($themes as $t) {
+ $nestedQueries[] = [
+ 'nested' => [
+ 'path' => "subject",
+ 'query' => [ 'term' => ['subject.code' => "$t" ] ]
+ ]
+ ];
+ }
+ return [
+ 'bool' => [
+ 'must' => $nestedQueries
+ ]
+ ];
+ }
+
+ public static function prepareDiscourse($entities) {
+ if(empty($entities)) {
+ return [];
+ }
+ if(is_string($entities)) {
+ $entities = [$entities,];
+ }
+
+ return array_reduce($entities, function($res, $e) {
+ if(preg_match(config('corpusparole.bnf_ark_url_regexp'), $e)) {
+ array_push($res, $e);
+ } elseif(Utils::startsWith($e, config('corpusparole.bnf_ark_id_base'))) {
+ array_push($res, config('corpusparole.bnf_ark_base_url').$e);
+ }
+ return $res;
+ }, []);
+
+ }
+
+ public static function getDiscourseFilterPart($discourses) {
+ $subDiscQueries=array_map(function($d) {
+ return [ 'term' => ['discourse_types' => "$d" ]];
+ }, $discourses);
+
+ return [
+ 'bool' => [
+ 'must' => $subDiscQueries
+ ]
+ ];
+ }
+
}
--- a/server/src/app/Models/Document.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/app/Models/Document.php Thu Oct 20 12:56:24 2016 +0530
@@ -100,13 +100,13 @@
public function getDiscourseTypes() {
return array_values(array_filter($this->getTypes(), function($v) {
- return $v instanceof Literal && $v->getDatatypeUri() === Config::get('corpusparole.olac_discourse_type')['uri'];
+ return $v instanceof Resource && preg_match(config('corpusparole.bnf_ark_url_regexp'), $v->getUri());
}));
}
public function getOtherTypes() {
$res = array_values(array_filter($this->getTypes(), function($v) {
- return $v instanceof Resource || $v->getDatatypeUri() !== Config::get('corpusparole.olac_discourse_type')['uri'];
+ return !($v instanceof Resource) || !preg_match(config('corpusparole.bnf_ark_url_regexp'), $v->getUri());
}));
return $res;
}
@@ -190,15 +190,14 @@
//delete
foreach($this->getDiscourseTypes() as $discourseType) {
- $literalValue = new Literal($discourseType, null, Config::get('corpusparole.olac_discourse_type')['uri']);
- $this->getProvidedCHO()->delete('dc11:type', $literalValue);
- $this->currentDelta->getDeletedGraph()->add($this->getProvidedCHO(), 'dc11:type', new Literal($discourseType, null, Config::get('corpusparole.olac_discourse_type')['uri']));
+ $this->getProvidedCHO()->delete('dc11:type', $discourseType);
+ $this->currentDelta->getDeletedGraph()->addResource($this->getProvidedCHO(), 'dc11:type', $discourseType->getUri());
}
// and re-add them
foreach($discoursesTypes as $dType) {
- $this->getProvidedCHO()->add('dc11:type', new Literal($dType, null, Config::get('corpusparole.olac_discourse_type')['uri']));
- $this->currentDelta->getAddedGraph()->add($this->getProvidedCHO(), 'dc11:type', new Literal($dType, null, Config::get('corpusparole.olac_discourse_type')['uri']));
+ $this->getProvidedCHO()->addResource('dc11:type', $dType);
+ $this->currentDelta->getAddedGraph()->addResource($this->getProvidedCHO(), 'dc11:type', $dType);
}
$this->clearMemoizationCache();
--- a/server/src/app/Repositories/RdfDocumentRepository.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/app/Repositories/RdfDocumentRepository.php Thu Oct 20 12:56:24 2016 +0530
@@ -154,6 +154,29 @@
}
$qFilterParts[] = CorpusFilterManager::getLanguagesFilterPart($languages);
}
+ if(array_key_exists('location', $filters) && !empty($filters['location'])) {
+ $location = $filters['location'];
+ if(is_array($location)) {
+ $location = $location[0]; // we know it is not empty
+ }
+ $qFilterParts[] = CorpusFilterManager::getLocationFilterPart($location);
+ }
+ if(array_key_exists('themes', $filters) && !empty($filters['themes'])) {
+ $themes = $filters['themes'];
+ if(is_string($themes)) {
+ $themes = [$themes,]; // we know it is not empty
+ }
+ $qFilterParts[] = CorpusFilterManager::getThemeFilterPart($themes);
+ }
+ if(array_key_exists('discourses', $filters) && !empty($filters['discourses'])) {
+ $discourses = $filters['discourses'];
+ if(is_string($discourses)) {
+ $discourses = [$discourses,]; // we know it is not empty
+ }
+ $qFilterParts[] = CorpusFilterManager::getDiscourseFilterPart($discourses);
+ }
+
+ Log::debug("queries : ".print_r($qFilterParts, true));
$query = [
'index' => config('corpusparole.elasticsearch_index'),
--- a/server/src/config/corpusparole.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/config/corpusparole.php Thu Oct 20 12:56:24 2016 +0530
@@ -132,6 +132,7 @@
'bnf_base_url' => 'http://data.bnf.fr/',
'bnf_ark_base_url' => 'http://ark.bnf.fr/',
'bnf_ark_url_regexp' => '/http[s]?\:\/\/(?:data|ark)\.bnf\.fr\/(ark\:\/12148\/[[:alnum:]]+)\/?/',
+ 'bnf_ark_id_base' => "ark:/12148/",
'bnf_cache_expiration' => 60*24*30,
'bnf_max_ids' => 5,
'bnf_query_url' => 'http://data.bnf.fr/sparql',
--- a/server/src/config/version.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/config/version.php Thu Oct 20 12:56:24 2016 +0530
@@ -8,5 +8,5 @@
| Must be incremented as needed.
|
*/
- 'version' => '0.0.2'
+ 'version' => '0.0.3'
];
--- a/server/src/tests/Libraries/Filters/CorpusFilterManagerTest.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/tests/Libraries/Filters/CorpusFilterManagerTest.php Thu Oct 20 12:56:24 2016 +0530
@@ -17,6 +17,18 @@
}
/**
+ * test prepare languages unknown
+ *
+ * @return void
+ */
+ public function testPrepareLanguagesUnkown()
+ {
+ $languagesInput = ['foobar'];
+ $languagesOutput = CorpusFilterManager::prepareLanguages($languagesInput);
+ $this->assertEquals($languagesOutput, ['http://lexvo.org/id/iso639-3/foobar']);
+ }
+
+ /**
* test prepare languages addPrefix
*
* @return void
@@ -59,7 +71,7 @@
*/
public function testPrepareLanguagesRecusionComplex()
{
- $languagesInput = ['fra', 'http://lexvo.org/id/iso639-3/gsw', 'corpus-oil', 'corpus-regional'];
+ $languagesInput = ['fra', 'http://lexvo.org/id/iso639-3/gsw', 'corpus-oil', 'corpus-regionals'];
$languagesOutput = CorpusFilterManager::prepareLanguages($languagesInput);
sort($languagesOutput);
$languagesExpected = ['http://lexvo.org/id/iso639-3/fra', 'http://lexvo.org/id/iso639-3/gsw', 'http://lexvo.org/id/iso639-3/pcd',
@@ -69,5 +81,117 @@
$this->assertEquals($languagesOutput, $languagesExpected);
}
+ /**
+ * test prepare location no operation
+ *
+ * @return void
+ */
+ public function testPrepareLocationNoOp()
+ {
+ $locationInput = '3030293';
+ $locationOutput = CorpusFilterManager::prepareLocation($locationInput);
+ $this->assertEquals('3030293', $locationOutput);
+ }
+
+ /**
+ * test prepare location array
+ *
+ * @return void
+ */
+ public function testPrepareLocationArray()
+ {
+ $locationInput = ['3030293', 'foobar'];
+ $locationOutput = CorpusFilterManager::prepareLocation($locationInput);
+ $this->assertEquals('3030293', $locationOutput);
+ }
+
+
+ /**
+ * test prepare location unknown
+ *
+ * @return void
+ */
+ public function testPrepareLocationUnknown()
+ {
+ $locationInput = 'foobar';
+ $locationOutput = CorpusFilterManager::prepareLocation($locationInput);
+ $this->assertEquals('foobar', $locationOutput);
+ }
+
+ /**
+ * test prepare location geonames
+ *
+ * @return void
+ */
+ public function testPrepareLocationGeonames()
+ {
+ $locationInput = 'http://sws.geonames.org/3030293';
+ $locationOutput = CorpusFilterManager::prepareLocation($locationInput);
+ $this->assertEquals('3030293', $locationOutput);
+ }
+
+ /**
+ * test prepare location geonames array
+ *
+ * @return void
+ */
+ public function testPrepareLocationGeonamesArray()
+ {
+ $locationInput = ['http://sws.geonames.org/3030293', 'http://www.geonames.org/3017382'];
+ $locationOutput = CorpusFilterManager::prepareLocation($locationInput);
+ $this->assertEquals('3030293', $locationOutput);
+ }
+
+
+ /**
+ * test prepare themes noop
+ *
+ * @return void
+ */
+ public function testPrepareThemesNoOp()
+ {
+ $themesInput = ['ark:/12148/cb11937931x', 'ark:/12148/cb11946662b', 'ark:/12148/cb13318415c'];
+ $themesOutput = CorpusFilterManager::prepareTheme($themesInput);
+ $this->assertEquals($themesOutput, $themesInput);
+ }
+
+ /**
+ * test prepare themes full url
+ *
+ * @return void
+ */
+ public function testPrepareThemesFullUrl()
+ {
+ $themesInput = ['http://ark.bnf.fr/ark:/12148/cb11937931x', 'http://data.bnf.fr/ark:/12148/cb11946662b', 'https://ark.bnf.fr/ark:/12148/cb13318415c'];
+ $themesOutput = CorpusFilterManager::prepareTheme($themesInput);
+ $this->assertEquals($themesOutput, ['ark:/12148/cb11937931x', 'ark:/12148/cb11946662b', 'ark:/12148/cb13318415c']);
+ }
+
+
+ /**
+ * test prepare themes full url
+ *
+ * @return void
+ */
+ public function testPrepareThemesUnknown()
+ {
+ $themesInput = ['ark:/12148/cb11937931x', 'foo', 'ark:/12148/cb11946662b', 'ark:/12148/cb13318415c', 'bar'];
+ $themesOutput = CorpusFilterManager::prepareTheme($themesInput);
+ $this->assertEquals($themesOutput, ['ark:/12148/cb11937931x', 'ark:/12148/cb11946662b', 'ark:/12148/cb13318415c']);
+ }
+
+ /**
+ * test prepare themes mix
+ *
+ * @return void
+ */
+ public function testPrepareThemesMix()
+ {
+ $themesInput = ['ark:/12148/cb11937931x', 'foo', 'http://data.bnf.fr/ark:/12148/cb11946662b', 'ark:/12148/cb13318415c', 'bar'];
+ $themesOutput = CorpusFilterManager::prepareTheme($themesInput);
+ $this->assertEquals($themesOutput, ['ark:/12148/cb11937931x', 'ark:/12148/cb11946662b', 'ark:/12148/cb13318415c']);
+ }
+
+
}
--- a/server/src/tests/Models/DocumentTest.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/tests/Models/DocumentTest.php Thu Oct 20 12:56:24 2016 +0530
@@ -140,7 +140,7 @@
public function testGetOtherTypes() {
$doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
- $this->assertCount(5, $doc->getOtherTypes(), "types array must be of size 5");
+ $this->assertCount(6, $doc->getOtherTypes(), "types array must be of size 5");
foreach($doc->getTypes() as $type) {
$this->assertThat(
@@ -156,12 +156,11 @@
public function testGetDiscourseTypes() {
$doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
- $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3");
+ $this->assertCount(2, $doc->getDiscourseTypes(), "types array must be of size 3");
- $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $doc->getDiscourseTypes(), "Result contains only literals");
+ $this->assertContainsOnlyInstancesOf("EasyRdf\Resource", $doc->getDiscourseTypes(), "Result contains only Resources");
$type = $doc->getDiscourseTypes()[0];
- $this->assertEquals("narrative", $type->getValue(), "discourse type is narrative");
- $this->assertEquals("http://www.language-archives.org/OLAC/1.1/discourse-type", $type->getDatatypeUri(), "discourse type url");
+ $this->assertEquals("http://ark.bnf.fr/ark:/12148/cb11932135w", $type->getUri(), "discourse type is cb11932135w");
}
public function testCloneDocument() {
@@ -188,14 +187,14 @@
public function testUpdateDiscourseTypes() {
- $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic'];
+ $newDiscourseTypes = ["http://ark.bnf.fr/ark:/12148/cb11932135w" , "http://ark.bnf.fr/ark:/12148/cb13319048g", "http://ark.bnf.fr/ark:/12148/cb11949715t" , "http://ark.bnf.fr/ark:/12148/cb119783362"];
$doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
- $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3");
+ $this->assertCount(2, $doc->getDiscourseTypes(), "types array must be of size 2");
$doc->updateDiscourseTypes($newDiscourseTypes);
- $this->assertCount(5, $doc->getDiscourseTypes(), "types array must be of size 5");
+ $this->assertCount(4, $doc->getDiscourseTypes(), "types array must be of size 4");
$discourseTypes = $doc->getDiscourseTypes();
foreach($newDiscourseTypes as $dt) {
@@ -206,7 +205,7 @@
public function testUpdateDiscourseTypesDelta() {
- $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic'];
+ $newDiscourseTypes = ["http://ark.bnf.fr/ark:/12148/cb11932135w" , "http://ark.bnf.fr/ark:/12148/cb13319048g", "http://ark.bnf.fr/ark:/12148/cb11949715t" , "http://ark.bnf.fr/ark:/12148/cb119783362"];
$doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']);
@@ -221,13 +220,13 @@
$this->assertEquals(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $delta->getDeletedGraph()->getUri(), "uri of deleted graph must be ok");
$this->assertEquals(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $delta->getAddedGraph()->getUri(), "uri of added graph must be ok");
- $this->assertEquals(3, $delta->getDeletedGraph()->countTriples(), "deleted graph must have only 3 triples");
- $this->assertEquals(5, $delta->getAddedGraph()->countTriples(), "deleted graph must have only 5 triples");
+ $this->assertEquals(2, $delta->getDeletedGraph()->countTriples(), "deleted graph must have only 2 triples");
+ $this->assertEquals(4, $delta->getAddedGraph()->countTriples(), "deleted graph must have only 4 triples");
- $resQueryDiscourseType = $delta->getAddedGraph()->allLiterals($doc->getProvidedCHO(), 'dc11:type');
+ $resQueryDiscourseType = $delta->getAddedGraph()->allResources($doc->getProvidedCHO(), 'dc11:type');
foreach($resQueryDiscourseType as $dt) {
- $this->assertInstanceOf(EasyRdf\Literal::class, $dt, "This must be a litteral");
- $this->assertEquals('http://www.language-archives.org/OLAC/1.1/discourse-type', $dt->getDatatypeUri(), "The type of the Litteral must be correct");
+ $this->assertInstanceOf(EasyRdf\Resource::class, $dt, "This must be a Resource");
+ $this->assertRegexp(config('corpusparole.bnf_ark_url_regexp'), $dt->getUri(), "The resource uri must be bnf ark");
}
foreach($newDiscourseTypes as $dt) {
$this->assertContains($dt, $resQueryDiscourseType, "all discourse types must be in result list");
--- a/server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php Thu Oct 20 12:54:07 2016 +0530
+++ b/server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php Thu Oct 20 12:56:24 2016 +0530
@@ -210,7 +210,8 @@
public function testSave() {
$doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", $this->graph);
- $doc->updateDiscourseTypes(['oratory','drama','narrative']);
+ $updatedDiscourseTypes = ["http://ark.bnf.fr/ark:/12148/cb13319048g", "http://ark.bnf.fr/ark:/12148/cb11949715t" , "http://ark.bnf.fr/ark:/12148/cb119783362"];
+ $doc->updateDiscourseTypes($updatedDiscourseTypes);
$res = $this->documentRepository->save($doc);
@@ -220,18 +221,19 @@
$discoursesTypes = $res->getDiscourseTypes();
- $this->assertCount(3, $discoursesTypes, "types array must be of size 1");
+ $this->assertCount(3, $discoursesTypes, "types array must be of size 3");
- $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $discoursesTypes, "Result contains only literals");
+ $this->assertContainsOnlyInstancesOf("EasyRdf\Resource", $discoursesTypes, "Result contains only resources");
$newDiscoursesTypes = [];
foreach($discoursesTypes as $dt) {
- array_push($newDiscoursesTypes, $dt->getValue());
- $this->assertContains($dt->getValue(),['oratory','drama','narrative'],'Value in [oratory,drama,narrative]');
- $this->assertEquals("http://www.language-archives.org/OLAC/1.1/discourse-type", $dt->getDatatypeUri(), "discourse type url");
+ array_push($newDiscoursesTypes, $dt->getUri());
+ $this->assertContains($dt->getUri(), $updatedDiscourseTypes,"Value in ".print_r($updatedDiscourseTypes, true));
}
sort($newDiscoursesTypes);
- $this->assertEquals(['drama', 'narrative', 'oratory'], $newDiscoursesTypes, "array type must the same");
+ sort($updatedDiscourseTypes);
+
+ $this->assertEquals($updatedDiscourseTypes, $newDiscoursesTypes, "array type must the same");
}
public function testCount() {