예제 #1
0
 def list(self, request, *args, **kwargs):
     annotation_templates_dir = find_dir('annotation_templates')
     configs = []
     for config_file in pathlib.Path(annotation_templates_dir).glob('**/*.yml'):
         config = read_yaml(config_file)
         configs.append(config)
     template_groups_file = find_file(os.path.join('annotation_templates', 'groups.txt'))
     with open(template_groups_file) as f:
         groups = f.read().splitlines()
     logger.debug(f'{len(configs)} templates found.')
     return Response({'templates': configs, 'groups': groups})
예제 #2
0
 def list(self, request, *args, **kwargs):
     annotation_templates_dir = find_dir('annotation_templates')
     configs = []
     for config_file in pathlib.Path(annotation_templates_dir).glob('**/*.yml'):
         config = read_yaml(config_file)
         if config.get('image', '').startswith('/static') and settings.HOSTNAME:
             # if hostname set manually, create full image urls
             config['image'] = settings.HOSTNAME + config['image']
         configs.append(config)
     template_groups_file = find_file(os.path.join('annotation_templates', 'groups.txt'))
     with open(template_groups_file, encoding='utf-8') as f:
         groups = f.read().splitlines()
     logger.debug(f'{len(configs)} templates found.')
     return Response({'templates': configs, 'groups': groups})
예제 #3
0
def samples_paragraphs(request):
    """ Generate paragraphs example for preview
    """
    global _PARAGRAPH_SAMPLE

    if _PARAGRAPH_SAMPLE is None:
        with open(find_file('paragraphs.json'), encoding='utf-8') as f:
            _PARAGRAPH_SAMPLE = json.load(f)
    name_key = request.GET.get('nameKey', 'author')
    text_key = request.GET.get('textKey', 'text')

    result = []
    for line in _PARAGRAPH_SAMPLE:
        result.append({name_key: line['author'], text_key: line['text']})

    return HttpResponse(json.dumps(result), content_type='application/json')