// Path: nicta-ner/src/main/java/org/t3as/ner/resource/Configuration.java
// @Immutable
// public class Configuration {
// 
//     public static final String DEFAULT_CONFIG_RESOURCE = "config";
// 
//     public final boolean tracing;
//     private final FeatureMap featureMap;
// 
//     public Configuration() throws IOException, InterruptedException { this(false); }
// 
//     public Configuration(final boolean tracing) throws IOException, InterruptedException {
//         this(Configuration.class.getResourceAsStream(DEFAULT_CONFIG_RESOURCE), tracing);
//     }
// 
//     /** Constructor. Read in the config file. */
//     public Configuration(final InputStream config, final boolean tracing) throws IOException, InterruptedException {
//         this.tracing = tracing;
//         final Pattern COLONS = Pattern.compile(":");
//         final Splitter SPACES = Splitter.on(' ').trimResults().omitEmptyStrings();
//         final ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
// 
//         featureMap = new FeatureMap(tracing);
// 
//         try (final BufferedReader br = new BufferedReader(new InputStreamReader(config))) {
// 
//             for (String line; (line = br.readLine()) != null; ) {
//                 final String s = line.trim();
//                 if (s.startsWith("#")) continue;
//                 if (s.trim().isEmpty()) continue;
// 
//                 final String[] parts = COLONS.split(s, 2);
//                 switch (parts[0]) {
//                     case "Feature":
//                         final List<String> l = SPACES.limit(4).splitToList(parts[1]);
//                         final String featureType = l.get(0);
//                         final String entityType = l.get(1);
//                         final int weight = Integer.parseInt(l.get(2));
//                         final List<String> resourceNames = SPACES.splitToList(l.get(3));
//                         final Feature f = Feature.generateFeatureByName(featureType, weight, resourceNames);
//                         featureMap.addFeature(entityType, f);
//                         exec.execute(new FeatureInitialiserRunnable(f));
//                         break;
// 
//                     default:
//                         throw new IllegalArgumentException("Unexpected config keyword: '" + parts[0] + "'");
//                 }
//             }
//         }
//         exec.shutdown();
//         exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
//     }
// 
//     public FeatureMap getFeatureMap() { return featureMap; }
// 
//     private static class FeatureInitialiserRunnable implements Runnable {
// 
//         final Feature f;
// 
//         FeatureInitialiserRunnable(final Feature f) { this.f = f; }
// 
//         @Override
//         public void run() {
//             final String s = Objects.toStringHelper(f)
//                                     .add("weight", f.getWeight())
//                                     .add("resources", f.getResources())
//                                     .toString();
//             try { f.loadResources(); }
//             catch (final IOException e) { throw new RuntimeException("Could not load resources for feature: " + s, e); }
//         }
//     }
// }
// 
// Path: nicta-ner-common/src/main/java/org/t3as/ner/EntityClass.java
// public static final EntityClass DATE = new EntityClass("DATE");
// 
// Path: nicta-ner-common/src/main/java/org/t3as/ner/EntityClass.java
// public static final EntityClass UNKNOWN = new EntityClass("UNKNOWN");


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.google.common.collect.ImmutableMap.of;
import static org.t3as.ner.EntityClass.DATE;
import static org.t3as.ner.EntityClass.UNKNOWN;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
import org.t3as.ner.resource.Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
/*
 * #%L
 * NICTA t3as Named-Entity Recognition library
 * %%
 * Copyright (C) 2010 - 2014 NICTA
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
package org.t3as.ner;




public class NamedEntityAnalyserTest {

    static final EntityClass PER = new EntityClass("PERSON");
    static final EntityClass ORG = new EntityClass("ORGANIZATION");
    static final EntityClass LOC = new EntityClass("LOCATION");
    static final EntityClass ETH = new EntityClass("ETHNIC");

    private NamedEntityAnalyser namedEntityAnalyser;

    /**
     * NOTE: as can be seen in the results of this test there are lots of places where the NER can be improved!
     */
    @SuppressWarnings("MagicNumber")
    @DataProvider(name = "testProcess")
    public static Object[][] primeNumbers() throws IOException {
        return new Object[][]{
                {"John",
                 new ArrayList<Result>() {{
                     add(new Result("John", ORG, of(LOC, 6.0, PER, 7.5, ORG, 11.0, ETH, 0.0), none()));
                 }}},

                {"John and Jane Doe Doe live in New Zealand in November.",
                 new ArrayList<Result>() {{
                     add(new Result("John", ORG, of(LOC, 6.0, PER, 7.5, ORG, 11.0, ETH, 0.0), none()));
                     add(new Result("Jane Doe Doe", PER, of(LOC, 12.0, PER, 30.0, ORG, 15.0, ETH, 0.0), none()));
                     add(new Result("New Zealand", LOC, of(LOC, 47.0, PER, 8.75, ORG, 31.0, ETH, 15.0),
                                    of("prep", "in")));
// Path: nicta-ner/src/main/java/org/t3as/ner/resource/Configuration.java
// @Immutable
// public class Configuration {
// 
//     public static final String DEFAULT_CONFIG_RESOURCE = "config";
// 
//     public final boolean tracing;
//     private final FeatureMap featureMap;
// 
//     public Configuration() throws IOException, InterruptedException { this(false); }
// 
//     public Configuration(final boolean tracing) throws IOException, InterruptedException {
//         this(Configuration.class.getResourceAsStream(DEFAULT_CONFIG_RESOURCE), tracing);
//     }
// 
//     /** Constructor. Read in the config file. */
//     public Configuration(final InputStream config, final boolean tracing) throws IOException, InterruptedException {
//         this.tracing = tracing;
//         final Pattern COLONS = Pattern.compile(":");
//         final Splitter SPACES = Splitter.on(' ').trimResults().omitEmptyStrings();
//         final ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
// 
//         featureMap = new FeatureMap(tracing);
// 
//         try (final BufferedReader br = new BufferedReader(new InputStreamReader(config))) {
// 
//             for (String line; (line = br.readLine()) != null; ) {
//                 final String s = line.trim();
//                 if (s.startsWith("#")) continue;
//                 if (s.trim().isEmpty()) continue;
// 
//                 final String[] parts = COLONS.split(s, 2);
//                 switch (parts[0]) {
//                     case "Feature":
//                         final List<String> l = SPACES.limit(4).splitToList(parts[1]);
//                         final String featureType = l.get(0);
//                         final String entityType = l.get(1);
//                         final int weight = Integer.parseInt(l.get(2));
//                         final List<String> resourceNames = SPACES.splitToList(l.get(3));
//                         final Feature f = Feature.generateFeatureByName(featureType, weight, resourceNames);
//                         featureMap.addFeature(entityType, f);
//                         exec.execute(new FeatureInitialiserRunnable(f));
//                         break;
// 
//                     default:
//                         throw new IllegalArgumentException("Unexpected config keyword: '" + parts[0] + "'");
//                 }
//             }
//         }
//         exec.shutdown();
//         exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
//     }
// 
//     public FeatureMap getFeatureMap() { return featureMap; }
// 
//     private static class FeatureInitialiserRunnable implements Runnable {
// 
//         final Feature f;
// 
//         FeatureInitialiserRunnable(final Feature f) { this.f = f; }
// 
//         @Override
//         public void run() {
//             final String s = Objects.toStringHelper(f)
//                                     .add("weight", f.getWeight())
//                                     .add("resources", f.getResources())
//                                     .toString();
//             try { f.loadResources(); }
//             catch (final IOException e) { throw new RuntimeException("Could not load resources for feature: " + s, e); }
//         }
//     }
// }
// 
// Path: nicta-ner-common/src/main/java/org/t3as/ner/EntityClass.java
// public static final EntityClass DATE = new EntityClass("DATE");
// 
// Path: nicta-ner-common/src/main/java/org/t3as/ner/EntityClass.java
// public static final EntityClass UNKNOWN = new EntityClass("UNKNOWN");


// Path: nicta-ner/src/test/java/org/t3as/ner/NamedEntityAnalyserTest.java
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.google.common.collect.ImmutableMap.of;
import static org.t3as.ner.EntityClass.DATE;
import static org.t3as.ner.EntityClass.UNKNOWN;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
import org.t3as.ner.resource.Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/*
 * #%L
 * NICTA t3as Named-Entity Recognition library
 * %%
 * Copyright (C) 2010 - 2014 NICTA
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
package org.t3as.ner;




public class NamedEntityAnalyserTest {

    static final EntityClass PER = new EntityClass("PERSON");
    static final EntityClass ORG = new EntityClass("ORGANIZATION");
    static final EntityClass LOC = new EntityClass("LOCATION");
    static final EntityClass ETH = new EntityClass("ETHNIC");

    private NamedEntityAnalyser namedEntityAnalyser;

    /**
     * NOTE: as can be seen in the results of this test there are lots of places where the NER can be improved!
     */
    @SuppressWarnings("MagicNumber")
    @DataProvider(name = "testProcess")
    public static Object[][] primeNumbers() throws IOException {
        return new Object[][]{
                {"John",
                 new ArrayList<Result>() {{
                     add(new Result("John", ORG, of(LOC, 6.0, PER, 7.5, ORG, 11.0, ETH, 0.0), none()));
                 }}},

                {"John and Jane Doe Doe live in New Zealand in November.",
                 new ArrayList<Result>() {{
                     add(new Result("John", ORG, of(LOC, 6.0, PER, 7.5, ORG, 11.0, ETH, 0.0), none()));
                     add(new Result("Jane Doe Doe", PER, of(LOC, 12.0, PER, 30.0, ORG, 15.0, ETH, 0.0), none()));
                     add(new Result("New Zealand", LOC, of(LOC, 47.0, PER, 8.75, ORG, 31.0, ETH, 15.0),
                                    of("prep", "in")));
                     add(new Result("November", DATE, ImmutableMap.<EntityClass, Double>of(), of("prep", "in")));