src/p4l/management/commands/import_record.py
changeset 101 71532a54d1c4
parent 22 48ff361f96c8
child 102 53c9233a7684
--- a/src/p4l/management/commands/import_record.py	Mon Sep 16 09:36:19 2013 +0200
+++ b/src/p4l/management/commands/import_record.py	Fri Sep 20 00:03:31 2013 +0200
@@ -1,24 +1,22 @@
 # -*- coding: utf-8 -*-
 
+import logging
+from optparse import make_option
+
 from django.core.management import BaseCommand
 from django.db import reset_queries, transaction
-from optparse import make_option
+from rdflib import BNode, URIRef
+from rdflib.plugins.sparql import prepareQuery
+
+from p4l.management.constants import get_empty_graph, IIEP
 from p4l.models import Record, Language
 from p4l.utils import show_progress
-from rdflib import Graph, Namespace, BNode, URIRef
-from rdflib.plugins.sparql import prepareQuery
-import logging
 import xml.etree.cElementTree as ET
 
+
 logger = logging.getLogger(__name__)
 
 
-RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
-RDFS = Namespace("http://www.w3.org/2000/01/rdf-schema#")
-DCT = Namespace("http://purl.org/dc/terms/")
-IIEP = Namespace("http://www.iiep.unesco.org/plan4learning/model.owl#")
-UNESCO = Namespace("http://www.iiep.unesco.org/Ontology/")
-
 DEFAULT_LANGUAGE_URI = "http://psi.oasis-open.org/iso/639/#eng"
 
 DEFAULT_LANGUAGE_QUERY =  """SELECT ( COALESCE(?lang, ?other_lang) as ?main_lang) WHERE {
@@ -53,11 +51,6 @@
             if query in self.__query_cache \
             else self.__query_cache.setdefault(query, prepareQuery(query, initNs=namespaces))
 
-    def get_empty_graph(self):
-        record_graph = Graph()
-        record_graph.bind('iiep',"http://www.iiep.unesco.org/plan4learning/model.owl#")
-        record_graph.bind('dct',"http://purl.org/dc/terms/")
-        return record_graph
 
     def extract_single_value_form_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None):
         return next(self.extract_multiple_values_from_graph(graph, q, bindings, index, convert), None)
@@ -320,7 +313,7 @@
                 i += 1
                 writer = show_progress(i, total_records, "Processing record nb %d " % i, 50, writer=writer)
                 try:
-                    record_graph = self.get_empty_graph()
+                    record_graph = get_empty_graph()
                     record_graph.parse(data=ET.tostring(elem, encoding='utf-8'), format='xml')
                     # add transaction management
                     self.build_record(record_graph)