src/jocondelab/management/commands/export_rdf.py
author ymh <ymh.work@gmail.com>
Mon, 12 Mar 2018 15:09:11 +0100
changeset 374 7d0c029800d6
child 375 4889e93fcfad
permissions -rw-r--r--
add first version of rdf export command
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
374
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
# Copyright Institut de Recherche et d'Innovation © 2014
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
# contact@iri.centrepompidou.fr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
# Ce code a été développé pour un premier usage dans JocondeLab, projet du
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
# ministère de la culture et de la communication visant à expérimenter la
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
# recherche sémantique dans la base Joconde
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
# (http://jocondelab.iri-research.org/).
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
# Ce logiciel est régi par la licence CeCILL-C soumise au droit français et
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
# respectant les principes de diffusion des logiciels libres. Vous pouvez
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
# utiliser, modifier et/ou redistribuer ce programme sous les conditions
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
# de la licence CeCILL-C telle que diffusée par le CEA, le CNRS et l'INRIA
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
# sur le site "http://www.cecill.info".
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
# En contrepartie de l'accessibilité au code source et des droits de copie,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
# de modification et de redistribution accordés par cette licence, il n'est
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
# offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
# seule une responsabilité restreinte pèse sur l'auteur du programme,  le
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
# titulaire des droits patrimoniaux et les concédants successifs.
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
# A cet égard  l'attention de l'utilisateur est attirée sur les risques
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
# associés au chargement,  à l'utilisation,  à la modification et/ou au
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
# développement et à la reproduction du logiciel par l'utilisateur étant
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
# donné sa spécificité de logiciel libre, qui peut le rendre complexe à
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
# manipuler et qui le réserve donc à des développeurs et des professionnels
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
# avertis possédant  des  connaissances  informatiques approfondies.  Les
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
# utilisateurs sont donc invités à charger  et  tester  l'adéquation  du
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
# logiciel à leurs besoins dans des conditions permettant d'assurer la
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
# sécurité de leurs systèmes et ou de leurs données et, plus généralement,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
# à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
# Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
# pris connaissance de la licence CeCILL-C, et que vous en avez accepté les
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
# termes.
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
#
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
import bz2
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
import csv
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
import gc
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
import gzip
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
import logging
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
import re
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
from functools import reduce
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
from optparse import make_option
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
import rdflib
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
from django.core.management import BaseCommand
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
from django.core.management.base import CommandError
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
from django.core.paginator import Paginator
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
from django.db.models import Q
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
from rdflib import BNode, Graph, Literal, URIRef
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
from rdflib.namespace import DC, RDF, RDFS, SKOS, XSD, Namespace
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
from core.models import (AutrNoticeTerm, DomnNoticeTerm, EcolNoticeTerm,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
                         EpoqNoticeTerm, LieuxNoticeTerm, Notice, NoticeTerm,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
                         PeriNoticeTerm, ReprNoticeTerm, SrepNoticeTerm, Term,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
                         Thesaurus)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
from core.utils import show_progress
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
from jocondelab.models import ContributedTerm, Contribution
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
logger = logging.getLogger(__name__)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
JOCONDELAB_NS = Namespace("http://jocondelab.iri-research.org/ns/jocondelab/")
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
JOCONDELAB_DATA_NS = "https://jocondelab.iri-research.org/data/"
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
GEO = Namespace("http://www.w3.org/2003/01/geo/wgs84_pos#")
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
PREFIX_REGEXP = re.compile("^@prefix\s+")
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
fields = [
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    "label", "uri", "validated", "wp_label", "wp_alternative_label",
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    "thesaurus__label", "thesaurus__uri", "dbpedia_uri", "wikipedia_url",
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    "wikipedia_pageid", "wikipedia_revision_id", "alternative_wikipedia_url",
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    "alternative_wikipedia_pageid", "url_status", "link_semantic_level",
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    "wikipedia_edition"
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
]
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
rdf_namespaces = {
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    'thesaurus': {
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        'skos': SKOS,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        'rdf': RDF,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
        'dc': DC,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
    },
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    'term': {
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
        'skos': SKOS,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
        'rdf': RDF,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
        'rdfs': RDFS,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
        'dc': DC,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
        'xsd': XSD,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
        'geo': GEO,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
        'jcl': JOCONDELAB_NS
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    },
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
    'notice': {
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
        'rdf': RDF,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        'rdfs': RDFS,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        'dc': DC,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
        'jcl': JOCONDELAB_NS
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
    },
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
    'contributed_term': {
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        'rdf': RDF,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        'rdfs': RDFS,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
        'dc': DC,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        'jcl': JOCONDELAB_NS
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
    },
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    'contribution': {
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        'rdf': RDF,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
        'rdfs': RDFS,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
        'dc': DC,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
        'jcl': JOCONDELAB_NS
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
    }
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
}
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
PAGINATION_SIZE = 100
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
class Command(BaseCommand):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
    args = "file_path..."
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
    help = "Export jocondelab term link in rdf"
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
    option_list = BaseCommand.option_list + (
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
        make_option('-l', '--limit',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
            dest='limit',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
            type='int',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
            default=-1,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
            help='number of term to export. -1 is all (default)'
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
        ),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
        # make_option('-s', '--skip',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
        #     dest='skip',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
        #     type='int',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        #     default=0,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
        #     help='number of term to skip before export. default 0.'
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
        # ),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
        make_option('-b', '--batch',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
            dest='batch',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
            type='int',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
            default=100,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
            help='query batch default 100.'
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
        ),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
        make_option('-j', '--bzip2',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
            dest='bzip2',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
            action='store_true',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
            default=False,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
            help='bz2 compress'
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
        ),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
        make_option('-z', '--gzip',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
            dest='gzip',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
            action='store_true',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
            default=False,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
            help='gzip compress'
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
        ),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
        make_option('--newline',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
            dest='newline',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
            action='store_true',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
            default=False,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
            help='show progress with newlines'
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
        ),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
    )
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
    def get_fields(self):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
        return fields
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
    def get_query(self):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
        return Term.objects.all().select_related(*[field.name for field in Term._meta.fields if isinstance(field, ForeignKey)]).order_by('uri').values_list(*fields)  # @UndefinedVariable
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
    def process_row(self, r):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
        return r
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
    def get_row_message(self, r):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
        return "Exporting term %s" % r[0]  # @IgnorePep8
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
    def bind_namespaces(self, g, namespaces):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
        for k,ns in namespaces.items():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
            g.bind(k,ns)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
    def define_extensions(self, g):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
        self.addN(g, [
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
            (JOCONDELAB_NS.wikipediaLabel, RDFS.subPropertyOf, SKOS.altLabel),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
            (JOCONDELAB_NS.wikipediaAlternativeLabel, RDFS.subPropertyOf, SKOS.altLabel),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
            # JOCONDELAB_NS.Thesaurus -> SKOS.ConceptScheme
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
            # JOCONDELAB_NS.Term -> SKOS.Concept
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
            # JOCONDELAB_NS.normalizedLabel -> SKOS.hiddenLabel
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
            # JOCONDELAB_NS.wikipediaPage -> range foaf:Document
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
            # <owl:ObjectProperty rdf:about="#wikipediaArticle">
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
            #     <rdfs:comment xml:lang="en">A Wikipedia article of which subject is the resource.</rdfs:comment>
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
            #     <rdfs:domain rdf:resource="#Feature"/>
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
            #     <rdfs:label xml:lang="en">wikipedia article</rdfs:label>
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
            #     <rdfs:range rdf:resource="#WikipediaArticle"/>
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
            # </owl:ObjectProperty>
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
            # JOCONDELAB_NS.wikipediaPageID ??
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
            # JOCONDELAB_NS.wikipediaPageRevision ??
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
            # JOCONDELAB_NS.alternativeWikipediaPage -> range foaf:Document
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
            # JOCONDELAB_NS.alternativeWikipediaPageID ??
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
            # JOCONDELAB_NS.dbpediaResource
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
            # JOCONDELAB_NS.urlStatus  cf: src/core/models/term.py
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
            #   (0, "null_result"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
            #   (1, "redirection"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
            #   (2, "homonyme"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
            #   (3, "match"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
            #   (4, "unsematized"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
            # JOCONDELAB_NS.linkSemanticLevel cf: src/core/models/term.py
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
            #   TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES = (
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
            #   (0, "--"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
            #   (1, "EE"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
            #   (2, "EI"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
            #   (3, "BM"),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
            #   (4, "NM"))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
            # JOCONDELAB_NS.linkValidated
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
            # JOCONDELAB_NS.linkValidationDate
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
            # JOCONDELAB_NS.linkValidator
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
            # JOCONDELAB_NS.wikipediaEdition
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
            # JOCONDELAB_NS.DbpediaField
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
            # JOCONDELAB_NS.dbpediaField
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
            # JOCONDELAB_NS.dbpediaFieldThumbnail
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
            # JOCONDELAB_NS.dbpediaFieldLabel
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
            # JOCONDELAB_NS.dbpediaFieldAbstract
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
            # JOCONDELAB_NS.DbpediaYear
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
            # JOCONDELAB_NS.dbpediaYear
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
            # JOCONDELAB_NS.dbpediaYearStart
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
            # JOCONDELAB_NS.dbpediaYearEnd
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
            # JOCONDELAB_NS.DbpediaGeo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
            # JOCONDELAB_NS.dbpediaGeo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
            # JOCONDELAB_NS.Notice
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
            # JOCONDELAB_NS.NoticeImage
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
            
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
            # JOCONDELAB_NS.YearInfo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
            # JOCONDELAB_NS.YearInfoStart
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
            # JOCONDELAB_NS.YearInfoEnd
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
            # JOCONDELAB_NS.noticeRef
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
            # JOCONDELAB_NS.noticeAdpt
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
            # JOCONDELAB_NS.noticeAppl
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
            # JOCONDELAB_NS.noticeAptn
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
            # JOCONDELAB_NS.noticeAttr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
            # JOCONDELAB_NS.noticeAutr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
            # JOCONDELAB_NS.noticeAutrTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
            # JOCONDELAB_NS.noticeBibl
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
            # JOCONDELAB_NS.noticeComm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
            # JOCONDELAB_NS.noticeContact
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
            # JOCONDELAB_NS.noticeCoor
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
            # JOCONDELAB_NS.noticeCopy
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
            # JOCONDELAB_NS.noticeDacq
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
            # JOCONDELAB_NS.noticeCata
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
            # JOCONDELAB_NS.noticeDation 
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
            # JOCONDELAB_NS.noticeDdpt
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
            # JOCONDELAB_NS.noticeDecv
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
            # JOCONDELAB_NS.noticeDeno
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
            # JOCONDELAB_NS.noticeDepo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
            # JOCONDELAB_NS.noticeDesc
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
            # JOCONDELAB_NS.noticeDesy
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
            # JOCONDELAB_NS.noticeDims
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
            # JOCONDELAB_NS.noticeDmaj
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
            # JOCONDELAB_NS.noticeDmis
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
            # JOCONDELAB_NS.noticeDomn
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
            # JOCONDELAB_NS.noticeDomnTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
            # JOCONDELAB_NS.noticeDrep
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
            # JOCONDELAB_NS.noticeEcol
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
            # JOCONDELAB_NS.noticeEcolTerm 
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
            # JOCONDELAB_NS.noticeEpoq
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
            # JOCONDELAB_NS.noticeEpoqTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
            # JOCONDELAB_NS.noticeEtat
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
            # JOCONDELAB_NS.noticeExpo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
            # JOCONDELAB_NS.noticeGene
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
            # JOCONDELAB_NS.noticeGeohi
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
            # JOCONDELAB_NS.noticeHist
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
            # JOCONDELAB_NS.noticeImage
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
            # JOCONDELAB_NS.noticeInsc
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
            # JOCONDELAB_NS.noticeInv 
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
            # JOCONDELAB_NS.noticeLabel
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
            # JOCONDELAB_NS.noticeLabo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
            # JOCONDELAB_NS.noticeLieux
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
            # JOCONDELAB_NS.noticeLieuxTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
            # JOCONDELAB_NS.noticeLoca
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
            # JOCONDELAB_NS.noticeLoca2
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
            # JOCONDELAB_NS.noticeMill
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
            # JOCONDELAB_NS.noticeMilu
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
            # JOCONDELAB_NS.noticeMosa
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
            # JOCONDELAB_NS.noticeMsgcom
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
            # JOCONDELAB_NS.noticeMuseo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
            # JOCONDELAB_NS.noticeNsda
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
            # JOCONDELAB_NS.noticeOnom
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
            # JOCONDELAB_NS.noticePaut
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
            # JOCONDELAB_NS.noticePdat
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
            # JOCONDELAB_NS.noticePdec
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
            # JOCONDELAB_NS.noticePeoc
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
            # JOCONDELAB_NS.noticePeri
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
            # JOCONDELAB_NS.noticePeriTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
            # JOCONDELAB_NS.noticePeru
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
            # JOCONDELAB_NS.noticePhot
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
            # JOCONDELAB_NS.noticePins
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
            # JOCONDELAB_NS.noticePlieux
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
            # JOCONDELAB_NS.noticePrep
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
            # JOCONDELAB_NS.noticePuti
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
            # JOCONDELAB_NS.noticeReda
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
            # JOCONDELAB_NS.noticeRefim
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
            # JOCONDELAB_NS.noticeRepr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
            # JOCONDELAB_NS.noticeReprTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
            # JOCONDELAB_NS.noticeSrep
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
            # JOCONDELAB_NS.noticeSrepTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
            # JOCONDELAB_NS.noticeStat
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
            # JOCONDELAB_NS.noticeTech
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
            # JOCONDELAB_NS.noticeTico
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
            # JOCONDELAB_NS.noticeTitr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
            # JOCONDELAB_NS.noticeUtil
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
            # JOCONDELAB_NS.noticeVideo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
            # JOCONDELAB_NS.noticeWww
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
            # JOCONDELAB_NS.noticeImage
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
            # JOCONDELAB_NS.noticeImageUrl
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
            # JOCONDELAB_NS.noticeYear
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
            # JOCONDELAB_NS.noticeYearStart
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
            # JOCONDELAB_NS.noticeYearEnd
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
            # JOCONDELAB_NS.ContributedTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
            # JOCONDELAB_NS.Contribution
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
            # JOCONDELAB_NS.contributionTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
            # JOCONDELAB_NS.contributionThesaurus
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
            # JOCONDELAB_NS.contributionNotice
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
            # JOCONDELAB_NS.contributionCount
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
        ])
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
    def add_n(self, g, triples):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
        for triple in triples:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
            g.add(triple)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
    def remove_namespace_declarations(self, rdf_str):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
        res_str = ""
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
        for line in rdf_str.splitlines():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
            if not PREFIX_REGEXP.match(line):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
                res_str += line + "\n"
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
        return res_str
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
    def export_namespaces(self, dest_file):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
        g = Graph()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
        namespaces = reduce(lambda res, k: dict(res, **rdf_namespaces[k]) , rdf_namespaces.keys(), {})
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
        self.bind_namespaces(g, namespaces)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
        g.serialize(dest_file, format='turtle')
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
    def export_objects(self, query, obj_name, build_object_graph, dest_file):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
        
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
        print("Exporting " + obj_name)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
        namespaces = rdf_namespaces.get(obj_name, {})
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
        progress_writer = None
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
        obj_query = query
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
        if self.limit>=0:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
            obj_query = query[:self.limit]
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
        obj_paginator = Paginator(obj_query, PAGINATION_SIZE)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
        obj_count = obj_paginator.count
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
        i = 0
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
        for page_nb in obj_paginator.page_range:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
            for obj in obj_paginator.page(page_nb):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
                g = Graph()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
                self.bind_namespaces(g, namespaces)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
                g = build_object_graph(g, obj)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
                i += 1
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
                progress_writer = show_progress(
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
                    i,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
                    obj_count,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
                    "Exporting " + obj_name,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
                    40,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
                    writer=progress_writer,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
                    newline=self.newline
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
                )
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
                dest_file.write(self.remove_namespace_declarations(g.serialize(format='turtle')))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
            gc.collect()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
    def export_thesaurus(self, g, thes):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
        thes_ref = URIRef(thes.uri)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
        self.add_n(g,[
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
            (thes_ref, RDF.type, JOCONDELAB_NS.Thesaurus),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
            (thes_ref, DC.title, Literal(thes.title, lang="fr")),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
            (thes_ref, DC.description, Literal(thes.description, lang="fr")),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
            (thes_ref, DC.identifier, Literal(thes.label))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
        ])
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
        return g
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
    def export_term(self, g, term):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
        term_ref = URIRef(term.uri)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
        self.add_n(g, [
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
            (term_ref, RDF.type, JOCONDELAB_NS.Term),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
            (term_ref, SKOS.inScheme, URIRef(term.thesaurus.uri)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
            (term_ref, DC.language, Literal(term.lang)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
            (term_ref, SKOS.prefLabel, Literal(term.label, lang=term.lang)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
            (term_ref, JOCONDELAB_NS.normalizedLabel, Literal(term.normalized_label, lang=term.lang)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
            (term_ref, DC.created, Literal(term.created_at)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
            (term_ref, JOCONDELAB_NS.urlStatus, Literal(term.url_status)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
            (term_ref, JOCONDELAB_NS.linkSemanticLevel, Literal(term.link_semantic_level)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
            (term_ref, JOCONDELAB_NS.linkValidated, Literal(term.validated)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
            (term_ref, JOCONDELAB_NS.wikipediaEdition, Literal(term.wikipedia_edition)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
            (term_ref, JOCONDELAB_NS.noticeNb, Literal(term.nb_notice)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
            (term_ref, JOCONDELAB_NS.illusratedNoticeNb, Literal(term.nb_illustrated_notice)),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
        ])
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
        if term.wp_label:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
            g.add((term_ref, JOCONDELAB_NS.wikipediaLabel, Literal(term.wp_label, lang=term.lang)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
        if term.wp_alternative_label:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
            g.add((term_ref, JOCONDELAB_NS.wikipediaAlternativeLabel, Literal(term.wp_alternative_label, lang=term.lang)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
        if term.wikipedia_url:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
            g.add((term_ref, JOCONDELAB_NS.wikipediaPage, URIRef(term.wikipedia_url)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
        if term.wikipedia_pageid:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
            g.add((term_ref, JOCONDELAB_NS.wikipediaPageID, Literal(term.wikipedia_pageid)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
        if term.wikipedia_revision_id:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
            g.add((term_ref, JOCONDELAB_NS.wikipediaPageRevision, Literal(term.wikipedia_revision_id)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
        if term.alternative_wikipedia_url:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
            g.add((term_ref, JOCONDELAB_NS.alternativeWikipediaPage, URIRef(term.alternative_wikipedia_url)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
        if term.alternative_wikipedia_pageid:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
            g.add((term_ref, JOCONDELAB_NS.alternativeWikipediaPageID, Literal(term.alternative_wikipedia_pageid)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
        
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
        if term.dbpedia_uri:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
            g.add((term_ref, JOCONDELAB_NS.dbpediaResource, URIRef(term.dbpedia_uri)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
        if term.validation_date:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
            g.add((term_ref, JOCONDELAB_NS.linkValidationDate, Literal(term.validation_date)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
        if term.validator:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
            g.add((term_ref, JOCONDELAB_NS.linkValidator, Literal(term.validator.username)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
        if term.parent:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
            g.add((term_ref, SKOS.broader, URIRef(term.parent.uri)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
        for alt_label in term.alternative_labels.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
            g.add((term_ref, SKOS.altLabel, Literal(alt_label.label, lang=alt_label.lang)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
        for db_field in term.dbpedia_fields.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
            dbp_field_bnode = BNode()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
            g.add((term_ref, JOCONDELAB_NS.dbpediaField, dbp_field_bnode))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
            g.add((dbp_field_bnode, RDF.type, JOCONDELAB_NS.DbpediaField))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
            g.add((dbp_field_bnode, DC.language, Literal(db_field.language_code)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
            g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldUri, URIRef(db_field.dbpedia_uri)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
            if db_field.thumbnail:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
                g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldThumbnail, URIRef(db_field.thumbnail)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
            if db_field.label:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
                g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldLabel, Literal(db_field.label, lang=db_field.language_code)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
            if db_field.abstract:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
                g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldAbstract, Literal(db_field.abstract, lang=db_field.language_code)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
        for dbp_year in term.years.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
            dbp_year_bnode = BNode()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
            g.add((term_ref, JOCONDELAB_NS.dbpediaYear, dbp_year_bnode))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
            g.add((dbp_year_bnode, RDF.type, JOCONDELAB_NS.YearInfo))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
            g.add((dbp_year_bnode, JOCONDELAB_NS.YearInfoStart, Literal(dbp_year.start_year)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
            g.add((dbp_year_bnode, JOCONDELAB_NS.YearInfoEnd, Literal(dbp_year.end_year)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
        for dbp_geo in term.geo.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
            dbp_geo_bnode = BNode()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
            g.add((term_ref, JOCONDELAB_NS.dbpediaGeo, dbp_geo_bnode))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
            g.add((dbp_geo_bnode, RDF.type, JOCONDELAB_NS.DbpediaGeo))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
            g.add((dbp_geo_bnode, GEO.lat, Literal(str(dbp_geo.latitude), datatype=XSD.double)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
            g.add((dbp_geo_bnode, GEO.long, Literal(str(dbp_geo.longitude), datatype=XSD.double)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
        
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
        return g
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
    def get_notice_uri(self, notice):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
        return JOCONDELAB_DATA_NS + "notice/" + notice.ref
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
    def export_notice(self, g, notice):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
        notice_uri = self.get_notice_uri(notice)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
        notice_ref = URIRef(notice_uri)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
        g.add((notice_ref, RDF.type, JOCONDELAB_NS.Notice))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
        for fieldName in [
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
            'ref', 'adpt', 'appl', 'aptn', 'attr', 'autr', 'bibl',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
            'comm', 'contact', 'coor', 'copy', 'dacq', 'data',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
            'dation', 'ddpt', 'decv', 'deno', 'depo', 'desc', 'desy',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
            'dims', 'dmaj', 'dmis', 'domn', 'drep', 'ecol', 'epoq',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
            'etat', 'expo', 'gene', 'geohi', 'hist', 'image', 'insc',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
            'inv', 'label', 'labo', 'lieux', 'loca', 'loca2', 'mill',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
            'milu', 'mosa', 'msgcom', 'museo', 'nsda', 'onom', 'paut',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
            'pdat', 'pdec', 'peoc', 'peri', 'peru', 'phot', 'pins',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
            'plieux', 'prep', 'puti', 'reda', 'refim', 'repr', 'srep',
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
            'stat', 'tech', 'tico', 'titr', 'util', 'video', 'www'
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
        ]:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
            fieldValue = getattr(notice, fieldName)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
            if fieldValue:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
                g.add((notice_ref, getattr(JOCONDELAB_NS, "notice"+fieldName.capitalize()), Literal(fieldValue)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
        termNbs = NoticeTerm.objects.filter(notice=notice).count()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
        totalTermNb = 0
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
        for fieldName in ['autr', 'domn', 'ecol', 'epoq', 'lieux', 'peri', 'repr', 'srep']:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
            
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
            termQuery = getattr(notice, fieldName + "_terms")
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
            for term in termQuery.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
                if term.thesaurus.label.lower() == fieldName:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
                    totalTermNb += 1
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
                    g.add((notice_ref, getattr(JOCONDELAB_NS, "notice"+fieldName.capitalize()+"Term"), URIRef(term.uri)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
        if totalTermNb != termNbs:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
            logger.critical("Bad term count for notice %s should be %s and is %s", notice_uri, termNbs, totalTermNb)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
        for notice_image in notice.images.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
            notice_image_bnode = BNode()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
            g.add((notice_ref, JOCONDELAB_NS.noticeImage, notice_image_bnode))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
            g.add((notice_image_bnode, RDF.type, JOCONDELAB_NS.NoticeImage))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
            g.add((notice_image_bnode, JOCONDELAB_NS.noticeImageUrl, URIRef(notice_image.url)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
            g.add((notice_image_bnode, JOCONDELAB_NS.noticeImageOrder, Literal(notice_image.order)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
            g.add((notice_image_bnode, JOCONDELAB_NS.noticeImageIsMain, Literal(notice_image.main)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
            g.add((notice_image_bnode, JOCONDELAB_NS.noticeImageIsLarge, Literal(notice_image.large)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
        for notice_year in notice.years.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
            notice_year_bnode = BNode()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
            g.add((notice_ref, JOCONDELAB_NS.noticeYear, notice_year_bnode))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
            g.add((notice_year_bnode, RDF.type, JOCONDELAB_NS.YearInfo))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
            g.add((notice_year_bnode, JOCONDELAB_NS.YearInfoStart, Literal(notice_year.start_year)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
            g.add((notice_year_bnode, JOCONDELAB_NS.YearInfoEnd, Literal(notice_year.end_year)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
        return g
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
    def get_contributed_term_uri(self, term):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
        return JOCONDELAB_DATA_NS + "contributed_term/" + str(term.id)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
    def export_contributed_term(self, g, term):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
        
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
        term_uri = self.get_contributed_term_uri(term)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
        term_ref = URIRef(term_uri)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
        g.add((term_ref, RDF.type, JOCONDELAB_NS.ContributedTerm))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
        g.add((term_ref, JOCONDELAB_NS.dbpediaResource, URIRef(term.dbpedia_uri)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
        if term.dbpedia_language:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
            g.add((term_ref, JOCONDELAB_NS.dbpediaLanguage, Literal(term.dbpedia_language)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
        for db_field in term.dbpedia_fields.all():
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
            dbp_field_bnode = BNode()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
            g.add((term_ref, JOCONDELAB_NS.dbpediaField, dbp_field_bnode))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
            g.add((dbp_field_bnode, RDF.type, JOCONDELAB_NS.DbpediaField))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
            g.add((dbp_field_bnode, DC.language, Literal(db_field.language_code)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
            g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldUri, URIRef(db_field.dbpedia_uri)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
            if db_field.thumbnail:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
                g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldThumbnail, URIRef(db_field.thumbnail)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
            if db_field.label:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
                g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldLabel, Literal(db_field.label, lang=db_field.language_code)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
            if db_field.abstract:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
                g.add((dbp_field_bnode, JOCONDELAB_NS.dbpediaFieldAbstract, Literal(db_field.abstract, lang=db_field.language_code)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
        return g
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
    def export_contribution(self, g, contribution):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
        contribution_uri = JOCONDELAB_DATA_NS + "contribution/" + str(contribution.id)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
        contribution_ref = URIRef(contribution_uri)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
        g.add((contribution_ref, RDF.type, JOCONDELAB_NS.Contribution))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
        g.add((contribution_ref, JOCONDELAB_NS.contributionTerm, URIRef(self.get_contributed_term_uri(contribution.term))))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
        if contribution.thesaurus:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
            g.add((contribution_ref, JOCONDELAB_NS.contributionThesaurus, URIRef(contribution.thesaurus.uri)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
        g.add((contribution_ref, JOCONDELAB_NS.contributionNotice, URIRef(self.get_notice_uri(contribution.notice))))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
        g.add((contribution_ref, JOCONDELAB_NS.contributionCount, Literal(contribution.contribution_count)))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
        return g
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
    def handle(self, *args, **options):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
        if len(args) != 1:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
            raise CommandError("This command takes exactly one argument")
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
        self.newline = options.get("newline", False)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
        self.limit = options.get("limit", -1)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
        filepath = args[0]
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
        bzip2 = options.get('bzip2', False)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
        gzip_opt = options.get('gzip', False)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
        if bzip2 and not filepath.endswith(".bz2"):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
            filepath += ".bz2"
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
        elif gzip_opt and not filepath.endswith(".gz"):
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
            filepath += ".gz"
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
        open_method = None
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
        open_args = []
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
        if bzip2:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
            open_method = bz2.BZ2File
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
            open_args = [filepath, 'wb', 9]
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
        elif gzip_opt:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
            open_method = gzip.GzipFile
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
            open_args = [filepath, 'wb', 9]
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
        else:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
            #open_method = codecs.open
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
            open_method = open
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
            #open_args = [filepath, 'wb', "utf-8"]
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
            open_args = [filepath, 'wb']
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
        term_query = Term.objects.select_related('thesaurus', 'alternative_labels', 'dbpedia_fields').order_by('id')
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
        if self.limit >= 0:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
            notice_term_query_filter = Q()
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
            for klass in [NoticeTerm, AutrNoticeTerm, DomnNoticeTerm, EcolNoticeTerm, EpoqNoticeTerm, LieuxNoticeTerm, PeriNoticeTerm, ReprNoticeTerm, SrepNoticeTerm]:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
                notice_term_query = klass.objects.filter(notice__id__in=Notice.objects.order_by('id')[:self.limit].values_list('id', flat=True))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
                notice_term_query_filter = notice_term_query_filter | Q(id__in=notice_term_query.values_list('term__id', flat=True))
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
            term_query = term_query.filter(notice_term_query_filter)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
        with open_method(*open_args) as dest_file:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
            self.export_namespaces(dest_file)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
            for query, namespaces, build_method in [
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
                (Thesaurus.objects.all(), 'thesaurus', self.export_thesaurus),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
                (term_query, 'term', self.export_term),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
                (Notice.objects.order_by('id').select_related().all(), 'notice', self.export_notice),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
                (ContributedTerm.objects.select_related().order_by('id').all(), 'contributed_term', self.export_contributed_term),
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
                (Contribution.objects.select_related().order_by('id').all(), 'contribution', self.export_contribution)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
            ]:
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
                self.export_objects(query, namespaces, build_method, dest_file)
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
# list of objects
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
# User
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
# Notice
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
# Term
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
# TermLabel
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
# Thesaurus
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
# NoticeImage
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
# NoticeTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
# Country
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
# DbpediaFields
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
# TermLinks
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
# DbpediaYears
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
# DbpediaGeo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
# ContributedTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
# ContributedFields
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
# Contribution
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
# ContributableTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
# TagcloudTerm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
# NoticeYears
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
# TERM_URL_STATUS_CHOICES
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
# TERM_URL_STATUS_CHOICES_TRANS
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
# TERM_URL_STATUS_DICT
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
# TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
# TERM_WK_LINK_SEMANTIC_LEVEL_DICT
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
# export : thesaurus,
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
# ref
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
# adpt
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
# appl
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
# aptn
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
# attr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
# bibl
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
# comm
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
# contact
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
# coor
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
# copy
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
# dacq
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
# data
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
# dation
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
# ddpt
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
# decv
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
# deno
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
# depo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
# desc
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
# desy
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
# dims
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
# dmaj
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
# dmis
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
# drep
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
# etat
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
# expo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
# gene
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
# geohi
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
# hist
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
# image
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
# insc
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
# inv
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
# label
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
# labo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
# loca
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
# loca2
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
# mill
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
# milu
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
# mosa
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
# msgcom
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
# museo
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
# nsda
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
# onom
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
# paut
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
# pdat
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
# pdec
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
# peoc
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
# peru
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
# phot
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
# pins
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
# plieux
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
# prep
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
# puti
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
# reda
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
# refim
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
# stat
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
# tech
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
# tico
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
# titr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
# util
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
# video
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
# www
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
# autr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
# domn
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
# ecol
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
# epoq
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
# lieux
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
# peri
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
# repr
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
# srep
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
7d0c029800d6 add first version of rdf export command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734