Java Code Examples for org.carrot2.core.Cluster#getAllDocuments()

The following examples show how to use org.carrot2.core.Cluster#getAllDocuments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopicsTransMetricProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private void storeNewsgroupTopics(List<Cluster> newsgroupTopics, CommunicationChannelDelta ccpDelta,
		TopicsTransMetric db) {
	db.getNewsgroupTopics().getDbCollection().drop();
	for (Cluster cluster : newsgroupTopics) {
		NewsgroupTopic newsgroupTopic = new NewsgroupTopic();
		db.getNewsgroupTopics().add(newsgroupTopic);
		CommunicationChannel communicationChannel = ccpDelta.getCommunicationChannel();
		newsgroupTopic.setNewsgroupName(communicationChannel.getOSSMeterId());
		newsgroupTopic.getLabels().addAll(cluster.getPhrases());
		newsgroupTopic.setNumberOfDocuments(cluster.getAllDocuments().size());
		for(Document document : cluster.getAllDocuments())
		{
			String[] uid = document.getStringId().split("\t");
			newsgroupTopic.getArticlesId().add(Long.valueOf(uid[1]));
		}
	}
	db.sync();
}
 
Example 2
Source File: TopicsTransMetricProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private void storeBugTrackerTopics(List<Cluster> bugTrackerTopics, BugTrackingSystemDelta btspDelta,
		TopicsTransMetric db) {
	db.getBugTrackerTopics().getDbCollection().drop();
	for (Cluster cluster : bugTrackerTopics) {
		BugTrackerTopic bugTrackerTopic = new BugTrackerTopic();
		db.getBugTrackerTopics().add(bugTrackerTopic);
		bugTrackerTopic.setBugTrackerId(btspDelta.getBugTrackingSystem().getOSSMeterId());
		bugTrackerTopic.getLabels().addAll(cluster.getPhrases());
		bugTrackerTopic.setNumberOfDocuments(cluster.getAllDocuments().size());
		for(Document document : cluster.getAllDocuments())
		{
			String[] uid = document.getStringId().split("\t");
			bugTrackerTopic.getCommentsId().add(uid[1]+"\t"+uid[2]);
		}
	}
	db.sync();
}
 
Example 3
Source File: CarrotClusteringEngine.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void clustersToNamedList(List<Cluster> outputClusters,
                                 List<NamedList<Object>> parent, boolean outputSubClusters, int maxLabels) {
  for (Cluster outCluster : outputClusters) {
    NamedList<Object> cluster = new SimpleOrderedMap<>();
    parent.add(cluster);

    // Add labels
    List<String> labels = outCluster.getPhrases();
    if (labels.size() > maxLabels) {
      labels = labels.subList(0, maxLabels);
    }
    cluster.add("labels", labels);

    // Add cluster score
    final Double score = outCluster.getScore();
    if (score != null) {
      cluster.add("score", score);
    }

    // Add other topics marker
    if (outCluster.isOtherTopics()) {
      cluster.add("other-topics", outCluster.isOtherTopics());
    }

    // Add documents
    List<Document> docs = outputSubClusters ? outCluster.getDocuments() : outCluster.getAllDocuments();
    List<Object> docList = new ArrayList<>();
    cluster.add("docs", docList);
    for (Document doc : docs) {
      docList.add(doc.getField(SOLR_DOCUMENT_ID));
    }

    // Add subclusters
    if (outputSubClusters && !outCluster.getSubclusters().isEmpty()) {
      List<NamedList<Object>> subclusters = new ArrayList<>();
      cluster.add("clusters", subclusters);
      clustersToNamedList(outCluster.getSubclusters(), subclusters,
              outputSubClusters, maxLabels);
    }
  }
}