Package org.dbpedia.spotlight.exceptions

Examples of org.dbpedia.spotlight.exceptions.ConfigurationException


    public TopicalClassificationConfiguration(String configFileName) throws ConfigurationException {
        //Read config properties:
        try {
            config.load(new FileInputStream(new File(configFileName)));
        } catch (IOException e) {
            throw new ConfigurationException("Cannot find configuration file "+configFileName,e);
        }

        if (config.getProperty(CLASSIFIER_TYPE) == null || config.getProperty(CLASSIFIER_PATH) == null)
            throw new ConfigurationException(String.format("Please validate your configuration in file %s for topical classification.",configFileName));

        File priors =  new File(config.getProperty(TOPICAL_PRIORS));
        if(!priors.exists())
            LOG.warn("Topical priors do not exist!");
View Full Code Here


            }
            if (NESpotter.entityTypes.get(OpenNLPUtil.OpenNlpModels.organization.toString()) == null) {
                buildNameModel(onlpModelDir, OpenNLPUtil.OpenNlpModels.organization.toString(), new URI(openNLPModelsURI.get(OpenNLPUtil.OpenNlpModels.organization.toString())),i18nLanguageCode);
            }
        } catch (Exception e) {
            throw new ConfigurationException("Error initializing NESpotter", e);
        }

    }
View Full Code Here

                    throw new IOException("could not find resource: " + resourcePath);
                }
            }
            return loadOpenNlpModel(modelType, in);
        } catch (IOException e) {
            throw new ConfigurationException("Could not load OpenNLP Model file.");
        }
    }
View Full Code Here

        //Read config properties:
        try {
            config.load(new FileInputStream(new File(fileName)));
        } catch (IOException e) {
            throw new ConfigurationException("Cannot find configuration file "+fileName,e);
        }

        // Validate spotters
        List<SpotterPolicy> spotters = getSpotterPolicies();
        LOG.info(String.format("Will load spotters: %s.",spotters));

        // Validate LingPipeSpotter
        if (spotters.contains(SpotterPolicy.LingPipeSpotter)) {
            //Load spotter configuration:
            spotterFile = config.getProperty("org.dbpedia.spotlight.spot.dictionary").trim();
            if(!new File(spotterFile).isFile()) {
                throw new ConfigurationException("Cannot find spotter file "+spotterFile);
            }
        }

        // Validate CoOccurrenceBasedSelector
        if (spotters.contains(SpotterPolicy.CoOccurrenceBasedSelector)) {

            //Check if all required parameters are there, trim whitespace
            String[] parameters = {"database.jdbcdriver", "database.connector", "database.user", "database.password",
                    "classifier.unigram", "classifier.ngram", "datasource"};

            for(String parameter : parameters) {
                try{
                    //Trim whitepsace from the parameter
                    config.setProperty(PREFIX_COOCCURRENCE_SELECTOR + parameter, config.getProperty(PREFIX_COOCCURRENCE_SELECTOR + parameter).trim());
                }catch(NullPointerException e){
                    //One of the configuration property required for this Spot selector was not there.
                    throw new ConfigurationException(String.format("Cannot find required configuration property '%s' for co-occurrence based spot selector %s.",PREFIX_COOCCURRENCE_SELECTOR + parameter, CoOccurrenceBasedSelector.class));
                }
            }

            //Check if all the required files are there:
            String[] parameterFiles = {"classifier.unigram", "classifier.ngram"};
            for(String fileparameter : parameterFiles) {
                String file = config.getProperty(PREFIX_COOCCURRENCE_SELECTOR + fileparameter);
                if(!new File(file).isFile()) {
                    throw new ConfigurationException("Cannot find required file '"+file+"' for configuration parameter "+PREFIX_COOCCURRENCE_SELECTOR + fileparameter);
                }
            }

            if(!config.getProperty(PREFIX_COOCCURRENCE_SELECTOR + "datasource").equalsIgnoreCase("ukwac") &&
               !config.getProperty(PREFIX_COOCCURRENCE_SELECTOR + "datasource").equalsIgnoreCase("google")) {
                throw new ConfigurationException(PREFIX_COOCCURRENCE_SELECTOR + "datasource must be one of 'ukwac' or 'google'.");
            }

            //check if database exists (if it's file)
            //jdbc:hsqldb:file:/data/spotlight/3.7/spotsel/ukwac_candidate;shutdown=true&readonly=true
            String configConnectorParam = PREFIX_COOCCURRENCE_SELECTOR + "database.connector";
            String connector = config.getProperty(configConnectorParam,"");
            try {
                if (connector.contains(":file:")) {
                    String[] parts = connector.split(":");
                    String path = parts[parts.length-1].split(";")[0];
                    if (!new File(path).exists())
                        throw new ConfigurationException(String.format("The file path %s specified for %s does not exist. Either remove CoOccurrenceBasedSelector from the list of spotters or set the correct path.",path,configConnectorParam));
                }
            } catch (Exception ignored) { LOG.debug("Unable to check database.connector string. "); }

        }

        // Validate CoOccurrenceBasedSelector
        if (spotters.contains(SpotterPolicy.NESpotter)) {
            if (!new File(getOpenNLPModelDir()).exists())
                throw new ConfigurationException(String.format("OpenNLP model directory was not found. It is required by %s.", NESpotter.class));
            setOpenNLPModelsURI();
        }

        //Validate AhoCorasickSpotter
        if(spotters.contains(SpotterPolicy.AhoCorasickSpotter))
        {
            //Load spotter configuration:
            spotterSurfaceForms = config.getProperty("org.dbpedia.spotlight.spot.ahocorasick.surfaceforms").trim();
            if(!new File(spotterSurfaceForms).isFile()) {
                throw new ConfigurationException("Cannot find surfaceForms file "+spotterSurfaceForms);
            }
        }

    }
View Full Code Here

    public List<SpotterPolicy> getSpotterPolicies() throws ConfigurationException {
        List<SpotterPolicy> policies = new ArrayList<SpotterPolicy>();
        String requestedSpotters = config.getProperty("org.dbpedia.spotlight.spot.spotters", "").trim();
        List<String> spotterNames = Arrays.asList(requestedSpotters.split(","));
        if (requestedSpotters.isEmpty() || spotterNames.size()==0) throw new ConfigurationException("Could not find 'org.dbpedia.spotlight.spot.spotters'. Please specify a comma-separated list of spotters to be loaded.");
        for (String s: spotterNames) {
            try {
                policies.add(SpotterPolicy.valueOf(s.trim()));
            } catch (java.lang.IllegalArgumentException e) {
                throw new ConfigurationException(String.format("Unknown spotter '%s' specified in 'org.dbpedia.spotlight.spot.spotters'.",s));
            }
        }
        return policies;
    }
View Full Code Here

        //Read config properties:
        try {
            config.load(new FileInputStream(new File(configFileName)));
        } catch (IOException e) {
            throw new ConfigurationException("Cannot find configuration file "+configFileName,e);
        }

        if (config.getProperty(CONFIG_DISAMBIGUATORS) == null)
            throw new ConfigurationException(String.format("Please specify a list of disambiguators in %s within your configuration file %s.",CONFIG_DISAMBIGUATORS,configFileName));

        List<DisambiguationPolicy> policies = getDisambiguatorPolicies();
        if (policies.size()==0)
            throw new ConfigurationException(String.format("Please specify a list of disambiguators in %s within your configuration file %s.",CONFIG_DISAMBIGUATORS,configFileName));

        LOG.info(String.format("Will load disambiguators: %s.",policies));

        /* Validate parameters */
    contextIndexDirectory = config.getProperty(CONFIG_CONTEXT_INDEX_DIR,"").trim();
    if(contextIndexDirectory==null) {
            throw new ConfigurationException(String.format("Please specify the path to the lucene index directory (context index) in %s within your configuration file %s.", CONFIG_CONTEXT_INDEX_DIR, configFileName));
        } else if (!new File(contextIndexDirectory).isDirectory()) {
      throw new ConfigurationException(String.format("The value %s=%s does not exist or is not a directory. Please update your config in %s.", CONFIG_CONTEXT_INDEX_DIR, contextIndexDirectory, configFileName));
    }
        contextIndexInMemory = config.getProperty("org.dbpedia.spotlight.index.loadToMemory", "false").trim().equals("true");

    }
View Full Code Here

    public List<DisambiguationPolicy> getDisambiguatorPolicies() throws ConfigurationException {
        List<DisambiguationPolicy> policies = new ArrayList<DisambiguationPolicy>();
        String requestedDisambiguators = config.getProperty(CONFIG_DISAMBIGUATORS, "").trim();
        List<String> disambiguatorNames = Arrays.asList(requestedDisambiguators.split(","));
        if (requestedDisambiguators.isEmpty() || disambiguatorNames.size()==0) throw new ConfigurationException(String.format("Could not find '%s'. Please specify a comma-separated list of disambiguators to be loaded.",CONFIG_DISAMBIGUATORS));
        for (String s: disambiguatorNames) {
            try {
                policies.add(DisambiguationPolicy.valueOf(s.trim()));
            } catch (IllegalArgumentException e) {
                throw new ConfigurationException(String.format("Unknown disambiguator '%s' specified in '%s'.",s,CONFIG_DISAMBIGUATORS));
            }
        }
        return policies;
    }
View Full Code Here

        //read config properties
        Properties config = new Properties();
        try {
            config.load(new FileInputStream(new File(fileName)));
        } catch (IOException e) {
            throw new ConfigurationException("Cannot find configuration file " + fileName, e);
        }

        DEFAULT_NAMESPACE = config.getProperty("org.dbpedia.spotlight.default_namespace", DEFAULT_NAMESPACE);
        dbpediaResource = config.getProperty("org.dbpedia.spotlight.default_namespace", dbpediaResource);

        DEFAULT_ONTOLOGY_PREFIX = config.getProperty("org.dbpedia.spotlight.default_ontology", DEFAULT_ONTOLOGY_PREFIX);
        dbpediaOntology =config.getProperty("org.dbpedia.spotlight.default_ontology", dbpediaOntology);

        DEFAULT_LANGUAGE_I18N_CODE = config.getProperty("org.dbpedia.spotlight.language_i18n_code", DEFAULT_LANGUAGE_I18N_CODE);
        i18nLanguageCode = config.getProperty("org.dbpedia.spotlight.language_i18n_code", "en");

        //Read the spotter configuration from the properties file
        spotterConfiguration = new SpotterConfiguration(fileName);

        disambiguatorConfiguration = new DisambiguatorConfiguration(fileName);

        //set spotterFile, indexDir...
        contextIndexDirectory = disambiguatorConfiguration.contextIndexDirectory;


        //optionally use separate candidate map
        candidateMapDirectory = config.getProperty("org.dbpedia.spotlight.candidateMap.dir", "").trim();
        if (candidateMapDirectory == null || !new File(candidateMapDirectory).isDirectory()) {
            LOG.warn("Could not use the candidateMap.dir provided. Will use index.dir both for context and candidate searching.");
            candidateMapDirectory = contextIndexDirectory;
        }
        candidateMapInMemory = config.getProperty("org.dbpedia.spotlight.candidateMap.loadToMemory", "false").trim().equals("true");

        try {
            BufferedReader r = new BufferedReader(new FileReader(new File(contextIndexDirectory, similarityThresholdsFile)));
            String line;
            similarityThresholds = new ArrayList<Double>();
            while ((line = r.readLine()) != null) {
                similarityThresholds.add(Double.parseDouble(line));
            }
        } catch (FileNotFoundException e) {
            throw new ConfigurationException("Similarity threshold file '" + similarityThresholdsFile + "' not found in index directory " + contextIndexDirectory, e);
        } catch (NumberFormatException e) {
            throw new ConfigurationException("Error parsing similarity value in '" + contextIndexDirectory + "/" + similarityThresholdsFile, e);
        } catch (IOException e) {
            throw new ConfigurationException("Error reading '" + contextIndexDirectory + "/" + similarityThresholdsFile, e);
        }

        taggerFile = config.getProperty("org.dbpedia.spotlight.tagging.hmm", "").trim();
        if (taggerFile == null || !new File(taggerFile).isFile()) {
            throw new ConfigurationException("Cannot find POS tagger model file " + taggerFile);
        }

        language = config.getProperty("org.dbpedia.spotlight.language", "English");


        stopWordsFile = config.getProperty("org.dbpedia.spotlight.data.stopWords." + language.toLowerCase(), "").trim();
        if ((stopWordsFile == null) || !new File(stopWordsFile.trim()).isFile()) {
            LOG.warn("Cannot find stopwords file '" + stopWordsFile + "'. Using default Lucene Analyzer StopWords.");
        } else {
            try {
                BufferedReader bufferedReader = new BufferedReader(new FileReader(stopWordsFile.trim()));
                String line = null;
                stopWords = new HashSet<String>();
                while ((line = bufferedReader.readLine()) != null) {
                    stopWords.add(line.trim());
                }
                bufferedReader.close();
            } catch (Exception e1) {
                LOG.error("Could not read stopwords file. Using default Lucene Analyzer StopWords");
            }
        }

        analyzer = Factory.analyzer().from(
                config.getProperty("org.dbpedia.spotlight.lucene.analyzer", "org.apache.lucene.analysis.standard.StandardAnalyzer"),
                config.getProperty("org.dbpedia.spotlight.lucene.version", "LUCENE_36"), stopWords);

        serverURI = config.getProperty("org.dbpedia.spotlight.web.rest.uri", "").trim();
        if (serverURI != null && !serverURI.endsWith("/")) {
            serverURI = serverURI.concat("/");
        }
        try {
            new URI(serverURI);
        } catch (URISyntaxException e) {
            throw new ConfigurationException("Server URI not valid.", e);
        }

        // Configure lucene to accept a larger number of or queries
        BooleanQuery.setMaxClauseCount(3072);
View Full Code Here

   * @throws InitializationException when something goes wrong on initialization
   */
  public SpotClassifier(String modelFile, OccurrenceDataProvider dataProvider, InstanceBuilder instanceBuilder)
      throws InitializationException {
    if (!new File(modelFile).exists()) //TODO Jo, please check during configuration if CoOccurrenceBasedSelector is in the config file, then check it at that point.
            throw new InitializationException("Error initiating SpotClassifier.",new ConfigurationException("Could not find file for org.dbpedia.spotlight.spot.classifier.unigram"));
    this.modelFile = modelFile;
    this.dataProvider = dataProvider;
    this.instanceBuilder = instanceBuilder;
    initialize();
  }
View Full Code Here

   * @throws org.json.JSONException Error while deserializing JSON file.
   */
  public AnnotatedDataset(File file, Format format, LingPipeFactory lingPipeFactory) throws IOException, ConfigurationException, JSONException {
        this.lingPipeFactory = lingPipeFactory;
        if (!file.exists()) {
            throw new ConfigurationException(String.format("Could not find dataset on path provided %s.",file.getAbsolutePath()));
        }

        switch (format) {

      case JSON:
View Full Code Here

TOP

Related Classes of org.dbpedia.spotlight.exceptions.ConfigurationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.