Package org.apache.stanbol.enhancer.topic

Examples of org.apache.stanbol.enhancer.topic.ClassifierException


            QueryResponse response = request.process(solrServer);
            SolrDocumentList results = response.getResults();
            for (SolrDocument result : results.toArray(new SolrDocument[0])) {
                String conceptUri = (String) result.getFirstValue(conceptUriField);
                if (conceptUri == null) {
                    throw new ClassifierException(String.format(
                        "Solr Core '%s' is missing required field '%s'.", solrCoreId, conceptUriField));
                }
                Float score = (Float) result.getFirstValue("score");

                // fetch metadata
                SolrQuery metadataQuery = new SolrQuery("*:*");
                // use filter queries to leverage the Solr cache explicitly
                metadataQuery.addFilterQuery(entryTypeField + ":" + METADATA_ENTRY);
                metadataQuery
                        .addFilterQuery(conceptUriField + ":" + ClientUtils.escapeQueryChars(conceptUri));
                metadataQuery.setFields(conceptUriField, broaderField, primaryTopicUriField);
                SolrDocument metadata = solrServer.query(metadataQuery).getResults().get(0);
                String primaryTopicUri = (String) metadata.getFirstValue(primaryTopicUriField);
                suggestedTopics.add(new TopicSuggestion(conceptUri, primaryTopicUri, metadata
                        .getFieldValues(broaderField), score));
            }
        } catch (SolrServerException e) {
            if ("unknown handler: /mlt".equals(e.getCause().getMessage())) {
                String message = String.format("SolrServer with id '%s' for topic engine '%s' lacks"
                                               + " configuration for the MoreLikeThisHandler", solrCoreId,
                    engineName);
                throw new ClassifierException(message, e);
            } else {
                throw new ClassifierException(e);
            }
        }
        if (suggestedTopics.size() <= 1) {
            // no need to apply the cutting heuristic
            return suggestedTopics;
View Full Code Here


                narrowerConcepts.add(result.getFirstValue(conceptUriField).toString());
            }
        } catch (SolrServerException e) {
            String msg = String.format("Error while fetching narrower topics of '%s' on Solr Core '%s'.",
                broadTopicId, solrCoreId);
            throw new ClassifierException(msg, e);
        }
        return narrowerConcepts;
    }
View Full Code Here

                }
            }
        } catch (SolrServerException e) {
            String msg = String.format("Error while fetching broader topics of '%s' on Solr Core '%s'.", id,
                solrCoreId);
            throw new ClassifierException(msg, e);
        }
        return broaderConcepts;
    }
View Full Code Here

            for (SolrDocument result : response.getResults()) {
                rootConcepts.add(result.getFirstValue(conceptUriField).toString());
            }
        } catch (SolrServerException e) {
            String msg = String.format("Error while fetching root topics on Solr Core '%s'.", solrCoreId);
            throw new ClassifierException(msg, e);
        }
        return rootConcepts;
    }
View Full Code Here

            solrServer.request(request);
            solrServer.commit();
        } catch (Exception e) {
            String msg = String.format("Error adding topic with id '%s' on Solr Core '%s'", conceptUri,
                solrCoreId);
            throw new ClassifierException(msg, e);
        }
    }
View Full Code Here

                solrServer.request(request);
            }
        } catch (Exception e) {
            String msg = String.format("Error invalidating topics [%s] on Solr Core '%s'",
                StringUtils.join(conceptIds, ", "), solrCoreId);
            throw new ClassifierException(msg, e);
        }
    }
View Full Code Here

        try {
            solrServer.deleteByQuery("*:*");
            solrServer.commit();
        } catch (Exception e) {
            String msg = String.format("Error deleting concepts from Solr Core '%s'", solrCoreId);
            throw new ClassifierException(msg, e);
        }
    }
View Full Code Here

    }

    @Override
    public void removeConcept(String conceptId) throws ClassifierException {
        if (conceptId == null || conceptId.isEmpty()) {
            throw new ClassifierException("conceptId must not be null or empty");
        }
        SolrServer solrServer = getActiveSolrServer();
        try {
            solrServer.deleteByQuery(conceptUriField + ":" + ClientUtils.escapeQueryChars(conceptId));
            solrServer.commit();
        } catch (Exception e) {
            String msg = String
                    .format("Error removing concept '%s' on Solr Core '%s'", conceptId, solrCoreId);
            throw new ClassifierException(msg, e);
        }
    }
View Full Code Here

            solrServer.request(request);
            // the commit is done by the caller in batch
        } catch (Exception e) {
            String msg = String.format("Error updating topic with id '%s' on Solr Core '%s'", conceptUri,
                solrCoreId);
            throw new ClassifierException(msg, e);
        }
        long stop = System.currentTimeMillis();
        log.debug("Sucessfully updated topic {} in {}s", conceptUri, (double) (stop - start) / 1000.);
    }
View Full Code Here

    synchronized public int updatePerformanceEstimates(boolean incremental) throws ClassifierException,
                                                                           TrainingSetException {
        checkTrainingSet();
        if (evaluationRunning) {
            throw new ClassifierException("Another evaluation is already running");
        }
        int updatedTopics = 0;
        File tmpfolder = null;
        try {
            tmpfolder = File.createTempFile("stanbol-evaluation-folder-", ".tmp");
            tmpfolder.delete();
            tmpfolder.mkdir();
            evaluationRunning = true;
            int cvFoldCount = 3; // 3-folds CV is hardcoded for now
            int cvIterationCount = 3; // make it possible to limit the number of folds to use

            // We will use the training set quite intensively, ensure that the index is packed and its
            // statistics are up to date
            getTrainingSet().optimize();

            // TODO: make the temporary folder path configurable with a property
            for (int cvFoldIndex = 0; cvFoldIndex < cvIterationCount; cvFoldIndex++) {
                updatedTopics = performCVFold(tmpfolder, cvFoldIndex, cvFoldCount, cvIterationCount,
                    incremental);
            }
            SolrServer solrServer = getActiveSolrServer();
            solrServer.optimize();
        } catch (ConfigurationException e) {
            throw new ClassifierException(e);
        } catch (IOException e) {
            throw new ClassifierException(e);
        } catch (SolrServerException e) {
            throw new ClassifierException(e);
        } finally {
            FileUtils.deleteQuietly(tmpfolder);
            evaluationRunning = false;
        }
        return updatedTopics;
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.topic.ClassifierException

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.