server/src/app/Libraries/CocoonUtils.php
author ymh <ymh.work@gmail.com>
Fri, 12 Feb 2016 15:30:32 +0100
changeset 122 b37fde30dd4a
parent 108 be2d3b30b2e0
child 145 49b75287c30b
permissions -rw-r--r--
correct problem of identifier
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
    /**
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
     * Extract id form cocoon url.
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
    /**
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    45
     * Extract id form corpus url.
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    46
     *
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    47
     * @return string
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    48
     */
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    49
    public static function getIdFromCorpusUri($uri) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    50
        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
    51
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    52
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    53
    /**
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
     * Create a Corpus resource id (purl url)
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
     *
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
     * @return string
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
     */
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    public static function getCorpusUriFromId($id) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    59
        if(strpos($id, config('corpusparole.corpus_id_scheme')) === 0) {
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    60
            $id = substr($id, strlen(config('corpusparole.corpus_id_scheme')));
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    61
        }
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        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
    63
    }
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
    public static function getCocoonPubUrl($id) {
122
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    66
        if(strpos($id, config('corpusparole.corpus_id_scheme')) === 0) {
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    67
            $id = substr($id, strlen(config('corpusparole.corpus_id_scheme')));
b37fde30dd4a correct problem of identifier
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    68
        }
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        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
    70
    }
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
108
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    72
    public static function isResourceCollection($res) {
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    73
        return $res instanceof Resource &&
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    74
            (strpos(strtolower($res->getUri()), "collection", strlen(config('corpusparole.cocoon_doc_id_base_uri'))) !== FALSE);
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    75
    }
be2d3b30b2e0 change isPartOf to edm:isGatheredInto for collections
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    76
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
}