// Path: src/main/java/org/elinker/core/spotter/FremeSpotter.java
// @Component
// @RequiredArgsConstructor
// public class FremeSpotter implements ApplicationListener<ContextRefreshedEvent> {
// 
//     @Value("${freme.ner.dictionary:}")
//     private String dictionary = "";
// 
//     private Boolean hasBuilt = false;
// 
//     private Trie.TrieBuilder builder;
// 
//     private Trie trie;
// 
//     private void buildDictionary() {
// 
//         if (dictionary == null || dictionary.isEmpty()) {
//             return;
//         }
// 
// 
//         builder = Trie.builder().removeOverlaps().caseInsensitive();
// 
//         try (Stream<String> stream = Files.lines(Paths.get(dictionary))) {
//             stream.forEach(s -> {
//                 builder.addKeyword(s);
//             });
//         } catch (IOException e) {
//             throw new InternalServerErrorException(String.format("It was not possible to read the spotter dictionary." +
//                     " Please check if the path is correct (%s)", dictionary));
//         }
//         trie = builder.build();
//     }
// 
//     public void addKey(String key) {
// 
//         if (dictionary == null || dictionary.isEmpty()) {
//             return;
//         }
// 
//         try {
//             builder.addKeyword(key);
//             trie = builder.build();
//             Files.write(Paths.get(dictionary), key.concat(System.lineSeparator()).getBytes(UTF_8), APPEND);
//         } catch (IOException e) {
//             throw new InternalServerErrorException("It was not possible to add a key into the spotter dictionary.");
//         }
// 
//     }
// 
//     public Collection<Emit> parseText(String text) {
//         if (trie != null) {
//             return trie.parseText(text);
//         }
//         return new ArrayList<>();
//     }
// 
//     @Override
//     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
//         if (!hasBuilt) {
//             buildDictionary();
//         }
// 
//     }
// 
// }


import org.elinker.core.spotter.FremeSpotter;
import org.springframework.beans.factory.annotation.Autowired;
import eu.freme.common.exception.BadRequestException;
import javax.annotation.PostConstruct;
import org.springframework.transaction.annotation.Transactional;
package org.elinker.core.api.java;






/**
 * FremeNER Java API for performing spotting, linking and dataset management.
 * This class is essentially a wrapper around the Scala API.
 *
 * @author Nilesh Chakraborty <nilesh@nileshc.com>
 */
public class FremeNer {
    private org.elinker.core.api.scala.FremeNer fremeNer = null;
    
    @Autowired
    Config config;

    @Autowired
// Path: src/main/java/org/elinker/core/spotter/FremeSpotter.java
// @Component
// @RequiredArgsConstructor
// public class FremeSpotter implements ApplicationListener<ContextRefreshedEvent> {
// 
//     @Value("${freme.ner.dictionary:}")
//     private String dictionary = "";
// 
//     private Boolean hasBuilt = false;
// 
//     private Trie.TrieBuilder builder;
// 
//     private Trie trie;
// 
//     private void buildDictionary() {
// 
//         if (dictionary == null || dictionary.isEmpty()) {
//             return;
//         }
// 
// 
//         builder = Trie.builder().removeOverlaps().caseInsensitive();
// 
//         try (Stream<String> stream = Files.lines(Paths.get(dictionary))) {
//             stream.forEach(s -> {
//                 builder.addKeyword(s);
//             });
//         } catch (IOException e) {
//             throw new InternalServerErrorException(String.format("It was not possible to read the spotter dictionary." +
//                     " Please check if the path is correct (%s)", dictionary));
//         }
//         trie = builder.build();
//     }
// 
//     public void addKey(String key) {
// 
//         if (dictionary == null || dictionary.isEmpty()) {
//             return;
//         }
// 
//         try {
//             builder.addKeyword(key);
//             trie = builder.build();
//             Files.write(Paths.get(dictionary), key.concat(System.lineSeparator()).getBytes(UTF_8), APPEND);
//         } catch (IOException e) {
//             throw new InternalServerErrorException("It was not possible to add a key into the spotter dictionary.");
//         }
// 
//     }
// 
//     public Collection<Emit> parseText(String text) {
//         if (trie != null) {
//             return trie.parseText(text);
//         }
//         return new ArrayList<>();
//     }
// 
//     @Override
//     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
//         if (!hasBuilt) {
//             buildDictionary();
//         }
// 
//     }
// 
// }


// Path: src/main/java/org/elinker/core/api/java/FremeNer.java
import org.elinker.core.spotter.FremeSpotter;
import org.springframework.beans.factory.annotation.Autowired;
import eu.freme.common.exception.BadRequestException;
import javax.annotation.PostConstruct;
import org.springframework.transaction.annotation.Transactional;

package org.elinker.core.api.java;






/**
 * FremeNER Java API for performing spotting, linking and dataset management.
 * This class is essentially a wrapper around the Scala API.
 *
 * @author Nilesh Chakraborty <nilesh@nileshc.com>
 */
public class FremeNer {
    private org.elinker.core.api.scala.FremeNer fremeNer = null;
    
    @Autowired
    Config config;

    @Autowired
    private FremeSpotter spotter;