# HG changeset patch # User veltr # Date 1381767676 -7200 # Node ID 766fed94b3b5f92980019fbc1f8a19c6ff791332 # Parent ca46b8e1b717d3a386772515ffb777db265d9035 Fixed a mistake diff -r ca46b8e1b717 -r 766fed94b3b5 src/jocondelab/management/commands/get_notice_years.py --- a/src/jocondelab/management/commands/get_notice_years.py Mon Oct 14 17:59:15 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -# -*- coding: utf-8 -*- -from django.core.management.base import BaseCommand -from core.models import (Notice, Thesaurus) -import re - -class Command(BaseCommand): - - def handle(self, *args, **options): - - millcache = {} - pericache = {} - yearre = re.compile("\d+") - rejectre = re.compile("\d-\d") - beforre = re.compile("av(\.|ant)? JC|- ", re.I) - splitre = re.compile("\s*[,;]\s*") - sieclere = re.compile("si..?cle", re.I) - millenairere = re.compile("mill..?naire",re.I) - moitiere = re.compile("moiti", re.I) - quartre = re.compile("quart", re.I) - - def getyear(millesime): - year = None - if not rejectre.search(millesime): - yearmatch = yearre.search(millesime) - if yearmatch: - year = int(millesime[yearmatch.start():yearmatch.end()]) - if beforre.search(millesime): - year = - year - if year > 2012: - year = None - if year is None: - print '!!!!', millesime - millcache[millesime] = year - return year - - def getperiod(p): - duration = 0 - counts = yearre.findall(p) - res = [] - avjc = False - if len(counts): - if millenairere.search(p): - duration = 1000 - avjc = True #Les millénaires positifs ne sont jamais utilisés, les négatifs ne sont pas toujours précisés - if sieclere.search(p): - duration = 100 - nb = int(counts[-1]) - if beforre.search(p): - avjc = True - start = duration * (nb - 1) - if avjc: - start = - start - duration - partial = False - if moitiere.search(p): - partial = True - duration /= 2 - if quartre.search(p): - partial = True - duration /= 4 - if len(counts) > 1 and not partial: - print '!!!!', p - return res - if len(counts) == 1 and partial: - print '!!!!', p - return res - if partial: - nb = int(counts[0]) - start += duration * (nb - 1) - if not avjc: - start += 1 - end = start + duration - 1 - res = [start, end] - return res - - qs = Notice.objects.iterator() - for notice in qs: - millfield = notice.mill - years = [] - if millfield: - print millfield - millesimes = splitre.split(millfield) - years = [millcache[m] if m in millcache else getyear(m) for m in millesimes] - years = [y for y in years if y is not None] - perifield = notice.peri - if not len(years) and perifield: - print perifield - periodes = splitre.split(perifield) - for p in periodes: - if not p in pericache: - pericache[p] = getperiod(p) - years += pericache[p] - if len(years): - print ' ---->', min(years), max(years) - \ No newline at end of file diff -r ca46b8e1b717 -r 766fed94b3b5 src/jocondelab/management/commands/import_extra_labels.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jocondelab/management/commands/import_extra_labels.py Mon Oct 14 18:21:16 2013 +0200 @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +''' +Created on Sep 19, 2013 + +@author: rvelt +''' + +from core.models import Term +from jocondelab.models import DbpediaFields +from django.core.management import BaseCommand +import csv +import os + +class Command(BaseCommand): + + args = "csv_file" + + help = "Import csv file containing label translations missing from DbPedia" + + def handle(self, *args, **options): + + filepath = os.path.abspath(args[0]) + self.stdout.write("Importing %s" % filepath) + + with open(filepath,'rb') as csv_file: + dialect = csv.Sniffer().sniff(csv_file.read(1024)) + csv_file.seek(0) + reader = csv.DictReader(csv_file, dialect=dialect) + for i,row in enumerate(reader): + print row + if row.get('language_code', None) and row.get('dbpedia_uri', None) and row.get('label', None): + qs = DbpediaFields.objects.filter( + language_code = row['language_code'], + dbpedia_uri = row['dbpedia_uri'] + ) + for f in qs: + f.label = row['label'] + f.save() \ No newline at end of file