<commit_before>package org.col.resources;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.reflect.ClassPath;
import org.col.api.vocab.AreaStandard;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Path("/vocab")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("static-method")
public class VocabResource {

  @SuppressWarnings("unused")
  private static final Logger LOG = LoggerFactory.getLogger(VocabResource.class);
  private final Map<String, Class<Enum<?>>> vocabs;

  public VocabResource() {
    Map<String, Class<Enum<?>>> enums = Maps.newHashMap();
    try {
      for (ClassPath.ClassInfo info : ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(AreaStandard.class.getPackage().getName())) {
        Class<?> clazz = info.load();
        if (clazz.isEnum()) {
          Class<Enum<?>> enumClazz = (Class<Enum<?>>) clazz;
          enums.put(enumClazz.getSimpleName().toLowerCase(), enumClazz);
        }
      }
    } catch (IOException e) {
      LOG.error("Failed to init enum class map", e);
    }
    vocabs = ImmutableMap.copyOf(enums);
  }

  @GET
  public List<Class<Enum<?>>> list() {<commit_msg>Expose also enums from parser api<commit_after>package org.col.resources;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.reflect.ClassPath;
import org.col.api.vocab.AreaStandard;
import org.gbif.nameparser.api.Rank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Path("/vocab")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("static-method")
public class VocabResource {

  @SuppressWarnings("unused")
  private static final Logger LOG = LoggerFactory.getLogger(VocabResource.class);
  private final Map<String, Class<Enum<?>>> vocabs;

  public VocabResource() {
    Map<String, Class<Enum<?>>> enums = Maps.newHashMap();
    try {
      for (Package p : Lists.newArrayList(AreaStandard.class.getPackage(), Rank.class.getPackage())) {
        LOG.debug("Scan package {} for enums", p);
        for (ClassPath.ClassInfo info : ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(p.getName())) {
          Class<?> clazz = info.load();
          if (clazz.isEnum()) {
            LOG.debug("Adding enum {} to vocabularies", clazz.getSimpleName());
            Class<Enum<?>> enumClazz = (Class<Enum<?>>) clazz;
            enums.put(enumClazz.getSimpleName().toLowerCase(), enumClazz);
          }
        }
      }
    } catch (IOException e) {
      LOG.error("Failed to init enum class map", e);
    }
    vocabs = ImmutableMap.copyOf(enums);
  }

  @GET
  public List<Class<Enum<?>>> list() {
{'fraction_non_alphanumeric': 0.14414144441114773, 'fraction_numerical': 0.001198681450404555, 'mean_word_length': 4.119631901840491, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6718904', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1094, 'n_words': 206}