server/src/app/Libraries/CocoonUtils.php
author ymh <ymh.work@gmail.com>
Thu, 09 Feb 2017 15:05:36 +0100
changeset 504 4ab820b387da
parent 502 74fba571487e
permissions -rw-r--r--
Correct the handling of created date. Should correct #0025744
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
namespace CorpusParole\Libraries;
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
108
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
     4
use EasyRdf\Resource;
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
     5
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
class CocoonUtils {
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
     8
    const OLAC_ROLES = [
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
     9
        'http://www.language-archives.org/OLAC/1.1/annotator',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    10
        'http://www.language-archives.org/OLAC/1.1/author',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    11
        'http://www.language-archives.org/OLAC/1.1/compiler',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    12
        'http://www.language-archives.org/OLAC/1.1/consultant',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    13
        'http://www.language-archives.org/OLAC/1.1/data_inputter',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    14
        'http://www.language-archives.org/OLAC/1.1/depositor',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    15
        'http://www.language-archives.org/OLAC/1.1/developer',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    16
        'http://www.language-archives.org/OLAC/1.1/editor',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    17
        'http://www.language-archives.org/OLAC/1.1/illustrator',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    18
        'http://www.language-archives.org/OLAC/1.1/interpreter',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    19
        'http://www.language-archives.org/OLAC/1.1/interviewer',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    20
        'http://www.language-archives.org/OLAC/1.1/participant',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    21
        'http://www.language-archives.org/OLAC/1.1/performer',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    22
        'http://www.language-archives.org/OLAC/1.1/photographer',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    23
        'http://www.language-archives.org/OLAC/1.1/recorder',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    24
        'http://www.language-archives.org/OLAC/1.1/researcher',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    25
        'http://www.language-archives.org/OLAC/1.1/research_participant',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    26
        'http://www.language-archives.org/OLAC/1.1/responder',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    27
        'http://www.language-archives.org/OLAC/1.1/signer',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    28
        'http://www.language-archives.org/OLAC/1.1/singer',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    29
        'http://www.language-archives.org/OLAC/1.1/speaker',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    30
        'http://www.language-archives.org/OLAC/1.1/sponsor',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    31
        'http://www.language-archives.org/OLAC/1.1/transcriber',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    32
        'http://www.language-archives.org/OLAC/1.1/translator',
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    33
    ];
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    34
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    /**
502
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    36
     * Extract id from cocoon url.
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
     *
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
     * @return string
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
     */
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    public static function getIdFromUri($uri) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    41
        return config('corpusparole.corpus_id_scheme').substr($uri, strlen(config('corpusparole.cocoon_doc_id_base_uri')));
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    }
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    /**
502
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    45
     * Extract Cocoon id from Cocoon url.
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    46
     *
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    47
     * @return string
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    48
     */
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    49
    public static function getCocoonIdFromCorpusUri($uri) {
504
4ab820b387da Correct the handling of created date. Should correct #0025744
ymh <ymh.work@gmail.com>
parents: 502
diff changeset
    50
        return substr($uri, strlen(config('corpusparole.corpus_doc_id_base_uri')));
502
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    51
    }
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    52
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 308
diff changeset
    53
    /**
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    54
     * Extract id form corpus url.
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    55
     *
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    56
     * @return string
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    57
     */
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    58
    public static function getIdFromCorpusUri($uri) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    59
        return config('corpusparole.corpus_id_scheme').substr($uri, strlen(config('corpusparole.corpus_doc_id_base_uri')));
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    60
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    61
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    62
    /**
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
     * Create a Corpus resource id (purl url)
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
     *
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
     * @return string
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
     */
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    public static function getCorpusUriFromId($id) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    68
        if(strpos($id, config('corpusparole.corpus_id_scheme')) === 0) {
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    69
            $id = substr($id, strlen(config('corpusparole.corpus_id_scheme')));
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    70
        }
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        return rtrim(config('corpusparole.corpus_doc_id_base_uri'),'/')."/$id";
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    }
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    public static function getCocoonPubUrl($id) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    75
        if(strpos($id, config('corpusparole.corpus_id_scheme')) === 0) {
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    76
            $id = substr($id, strlen(config('corpusparole.corpus_id_scheme')));
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    77
        }
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
        return rtrim(config('corpusparole.cocoon_doc_pub_base_uri'), '/')."/$id";
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    }
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
108
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    81
    public static function isResourceCollection($res) {
145
49b75287c30b correct backoffocie with new handle if format
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    82
        return $res instanceof Resource && (
49b75287c30b correct backoffocie with new handle if format
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    83
            (strpos(strtolower($res->getUri()), "collection", strlen(config('corpusparole.cocoon_doc_id_base_uri'))) !== FALSE) ||
49b75287c30b correct backoffocie with new handle if format
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    84
            (strpos(strtolower($res->getUri()), "collection", strlen(config('corpusparole.corpus_doc_id_base_uri'))) !== FALSE)
49b75287c30b correct backoffocie with new handle if format
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    85
        );
108
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    86
    }
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    87
308
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    88
    public static function getGeonamesidFromUrl($url) {
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    89
        $matches = [];
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    90
        if(preg_match(config('corpusparole.geonames_url_regexp'), $url, $matches) === 1) {
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    91
            return $matches[1];
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    92
        }
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    93
        else {
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    94
            return null;
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    95
        }
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    96
    }
e032d686d88e add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents: 145
diff changeset
    97
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
}