You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2023/02/11 22:19:34 UTC
[opennlp-sandbox] branch fixes_typos_and_grammar_issues_in_sandbox_components created (now 782c48b)
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a change to branch fixes_typos_and_grammar_issues_in_sandbox_components
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git
at 782c48b fixes typos and grammar issues in sandbox components
This branch includes the following new commits:
new 782c48b fixes typos and grammar issues in sandbox components
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[opennlp-sandbox] 01/01: fixes typos and grammar issues in sandbox components
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch fixes_typos_and_grammar_issues_in_sandbox_components
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git
commit 782c48b418d9ba8b61c307ffa4b85be5ee6cde31
Author: Martin Wiesner <ma...@hs-heilbronn.de>
AuthorDate: Sat Feb 11 23:19:27 2023 +0100
fixes typos and grammar issues in sandbox components
- cures typos
- cures grammar issues
- rewrites some old c-style array declarations
- modernizes resource handling along the path
---
.github/CONTRIBUTING.md | 2 +-
aws-ec2-testing-scripts/README.md | 2 +-
.../caseditor/CorpusExplorerView.java | 2 +-
.../caseditor/CorpusServerCasEditorInput.java | 2 +-
.../caseditor/DefaultCasDocumentProvider.java | 10 +-
.../namefinder/EntityContentProvider.java | 2 +-
.../corpus_server/connector/CSCasWriter.java | 2 +-
.../connector/CSQueueCollectionReader.java | 2 +-
.../opennlp/corpus_server/connector/UimaUtil.java | 10 +-
.../opennlp/corpus_server/TaskQueuesResource.java | 2 +-
.../taskqueue/MemoryTaskQueueService.java | 7 +-
.../corpus_server/taskqueue/TaskQueueService.java | 2 +-
.../opennlp/corpus_server/search/LuceneIndexer.xml | 2 +-
.../opennlp/corpus_server/impl/LuceneIndexer.java | 4 +-
.../corpus_server/impl/LuceneSearchService.java | 2 +-
.../opennlp/corpus_server/impl/UimaUtil.java | 10 +-
.../opennlp/corpus_server/impl/LuceneIndexer.xml | 2 +-
.../opennlp/corpus_server/tools/CorpusBackup.java | 20 +-
.../opennlp/corpus_server/tools/CreateCorpus.java | 8 +-
.../opennlp/addons/mallet/ClassifierModel.java | 8 +-
.../modelbuilder/DefaultModelBuilderUtil.java | 2 +-
.../addons/modelbuilder/KnownEntityProvider.java | 7 +-
.../opennlp/addons/modelbuilder/Modelable.java | 4 +-
.../classification/SimpleNaiveBayesClassifier.java | 2 +-
.../opennlp/utils/languagemodel/NoisyChannel.java | 4 +-
.../utils/regression/RegressionModelUtils.java | 2 +-
.../tools/cmdline/coref/CoreferencerTool.java | 6 +-
.../tools/cmdline/coref/TrainingParams.java | 2 +-
.../java/opennlp/tools/coref/AbstractLinker.java | 2 +-
.../src/main/java/opennlp/tools/coref/Linker.java | 38 +-
.../main/java/opennlp/tools/coref/LinkerMode.java | 2 +-
.../tools/coref/mention/AbstractMentionFinder.java | 2 +-
.../opennlp/tools/coref/mention/AbstractParse.java | 7 +-
.../opennlp/tools/coref/mention/HeadFinder.java | 12 +-
.../java/opennlp/tools/coref/mention/Mention.java | 7 +-
.../tools/coref/mention/MentionContext.java | 2 +-
.../tools/coref/mention/PTBMentionFinder.java | 7 +-
.../java/opennlp/tools/coref/mention/Parse.java | 66 +--
.../tools/coref/resolver/CommonNounResolver.java | 3 +-
.../tools/coref/resolver/DefiniteNounResolver.java | 3 +-
.../opennlp/tools/coref/resolver/IsAResolver.java | 3 +-
.../coref/resolver/NonReferentialResolver.java | 8 +-
.../tools/coref/resolver/PluralNounResolver.java | 3 +-
.../coref/resolver/PluralPronounResolver.java | 3 +-
.../tools/coref/resolver/ProperNounResolver.java | 3 +-
.../opennlp/tools/coref/resolver/Resolver.java | 10 +-
.../tools/coref/resolver/ResolverUtils.java | 60 +-
.../coref/resolver/SingularPronounResolver.java | 3 +-
.../coref/resolver/SpeechPronounResolver.java | 9 +-
.../java/opennlp/tools/coref/sim/GenderEnum.java | 4 +-
.../tools/coref/sim/MaxentCompatibilityModel.java | 2 +-
.../tools/coref/sim/SemanticCompatibility.java | 6 +-
.../opennlp/tools/coref/sim/SimilarityModel.java | 6 +-
.../tools/coref/sim/TrainSimilarityModel.java | 13 +-
.../muc/Muc6FullParseCorefSampleStreamFactory.java | 2 +-
.../opennlp/tools/lang/english/TreebankLinker.java | 21 +-
.../tools/lang/english/TreebankNameFinder.java | 2 +-
.../src/main/java/opennlp/tools/dl/DataReader.java | 2 +-
opennlp-dl/src/main/java/opennlp/tools/dl/RNN.java | 2 +-
.../src/main/java/opennlp/tools/dl/StackedRNN.java | 2 +-
opennlp-similarity/README.md | 12 +-
opennlp-similarity/README.txt | 2 +-
opennlp-similarity/RELEASE_NOTES.html | 2 +-
.../multithreaded/BingWebQueryRunnerThread.java | 5 +-
.../contentgen/multithreaded/cgRequestForm.html | 2 +-
.../apps/object_dedup/SimilarityAccessorBase.java | 7 +-
.../tools/apps/relevanceVocabs/POStags.java | 132 ++---
.../apps/relevanceVocabs/PhraseProcessor.java | 3 +-
.../tools/apps/relevanceVocabs/SentimentVocab.java | 9 +-
.../tools/apps/relevanceVocabs/SynonymMap.java | 637 ++++++++++-----------
.../tools/apps/review_builder/ParserConstants.java | 132 ++---
.../apps/review_builder/SentenceOriginalizer.java | 11 +-
.../review_builder/WebPageReviewExtractor.java | 4 +-
.../tools/apps/utils/email/EmailSender.java | 2 +-
.../tools/apps/utils/email/SMTP_Authenticator.java | 4 +-
.../tools/doc_classifier/DocClassifier.java | 8 +-
.../EmailTrainingSetFormer.java | 2 +-
.../java/opennlp/tools/fca/BasicLevelMetrics.java | 16 +-
.../java/opennlp/tools/fca/ConceptLattice.java | 6 +-
.../main/java/opennlp/tools/fca/FcaConverter.java | 3 +-
.../main/java/opennlp/tools/fca/FormalConcept.java | 16 +-
.../src/main/java/opennlp/tools/fca/Measures.java | 3 +-
.../tools/jsmlearning/IntersectionSetBuilder.java | 2 +-
.../tools/jsmlearning/ProfileReaderWriter.java | 5 +-
.../tools/jsmlearning/TreeKernelRunner.java | 2 +-
.../opennlp/tools/parse_thicket/ParseTreeNode.java | 8 +-
.../tools/parse_thicket/VerbNetProcessor.java | 14 +-
.../apps/MostFrequentWordsFromPageGetter.java | 17 +-
.../parse_thicket/apps/SnippetToParagraph.java | 5 +-
.../tools/parse_thicket/apps/WebPageExtractor.java | 2 +-
.../matching/NERPhraseGeneralizer.java | 24 +-
.../parse_thicket/matching/PhraseGeneralizer.java | 20 +-
.../LinguisticPatternStructure.java | 20 +-
.../pattern_structure/PhraseConcept.java | 27 +-
.../tools/similarity/apps/ContentGenerator.java | 2 +-
.../similarity/apps/ContentGeneratorSupport.java | 18 +-
.../opennlp/tools/similarity/apps/HitBase.java | 8 +-
.../similarity/apps/RelatedSentenceFinder.java | 15 +-
.../similarity/apps/RelatedSentenceFinderML.java | 22 +-
.../apps/SpeechRecognitionResultsProcessor.java | 4 +-
.../apps/WebSearchEngineResultsScraper.java | 2 +-
.../apps/solr/ContentGeneratorRequestHandler.java | 2 +-
.../apps/solr/IterativeQueryComponent.java | 2 +-
.../apps/solr/IterativeSearchRequestHandler.java | 2 +-
.../solr/SearchResultsReRankerRequestHandler.java | 4 +-
.../tools/similarity/apps/solr/WordDocBuilder.java | 12 +-
.../apps/solr/WordDocBuilderEndNotes.java | 13 +-
.../solr/WordDocBuilderSingleImageSearchCall.java | 12 +-
.../tools/similarity/apps/solr/solrconfig.xml | 14 +-
.../taxo_builder/TaxoQuerySnapshotMatcher.java | 14 +-
.../taxo_builder/TaxonomyExtenderViaMebMining.java | 2 -
.../apps/taxo_builder/TaxonomySerializer.java | 3 +-
.../tools/similarity/apps/utils/FileHandler.java | 4 +-
.../tools/similarity/apps/utils/PageFetcher.java | 2 +-
.../tools/similarity/apps/utils/ValueSortMap.java | 49 +-
.../main/java/opennlp/tools/stemmer/PStemmer.java | 12 +-
.../tools/textsimilarity/ParseTreeChunk.java | 12 +-
.../ParseTreeMatcherDeterministic.java | 3 +-
.../textsimilarity/SentencePairMatchResult.java | 2 +-
.../tools/textsimilarity/TextProcessor.java | 22 +-
.../chunker2matcher/ParserCacheSerializer.java | 50 +-
.../ParserChunker2MatcherProcessor.java | 93 +--
.../chunker2matcher/ParserConstants.java | 132 ++---
.../java/opennlp/tools/textsimilarity/readme.txt | 4 +-
.../DisambiguatorEvaluatorParams.java | 2 +-
.../disambiguator/DisambiguatorToolParams.java | 2 +-
.../tools/disambiguator/FeaturesExtractor.java | 41 +-
.../java/opennlp/tools/disambiguator/Lesk.java | 10 +-
.../disambiguator/OSCCWSDContextGenerator.java | 7 +-
.../opennlp/tools/disambiguator/WSDEvaluator.java | 11 +-
.../opennlp/tools/disambiguator/WSDParameters.java | 2 +-
.../opennlp/tools/disambiguator/WSDSample.java | 2 +-
.../tools/disambiguator/WSDSampleStream.java | 9 +-
.../tools/disambiguator/WSDisambiguator.java | 8 +-
.../tools/disambiguator/WSDisambiguatorME.java | 5 +-
.../java/opennlp/tools/disambiguator/WTDIMS.java | 5 -
.../tools/disambiguator/datareader/Paragraph.java | 9 +-
.../tools/disambiguator/datareader/Word.java | 4 +-
.../main/java/opennlp/summarization/Sentence.java | 4 +-
.../LexChainingKeywordExtractor.java | 4 +-
.../lexicalchaining/LexicalChainingSummarizer.java | 10 +-
.../summarization/lexicalchaining/Word.java | 4 +-
.../lexicalchaining/WordRelation.java | 2 +-
.../WordRelationshipDetermination.java | 11 +-
.../opennlp/summarization/meta/MetaSummarizer.java | 6 +-
.../preprocess/DefaultDocProcessor.java | 8 +-
.../summarization/preprocess/PorterStemmer.java | 2 +-
.../opennlp/summarization/textrank/TextRank.java | 11 +-
.../src/main/resources/htmls/annotation-editor.js | 4 +-
.../src/main/resources/htmls/opennlp-demo.js | 2 +-
.../wikinews_importer/AnnotatingMarkupParser.java | 2 +-
.../apache/opennlp/wikinews_importer/UimaUtil.java | 10 +-
152 files changed, 1091 insertions(+), 1251 deletions(-)
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index caa51b8..5e06386 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -8,4 +8,4 @@ To make the process smooth for the project *committers* (those who review and ac
Please check out the [How to get involved](https://opennlp.apache.org/get-involved.html) to understand how contributions are made.
A detailed list of coding standards can be found at [Apache OpenNLP Code Conventions](https://opennlp.apache.org/code-conventions.html) which also contains a list of coding guidelines that you should follow.
-For pull requests, there is a [check list](PULL_REQUEST_TEMPLATE.md) with criteria for acceptable contributions.
+For pull requests, there is a [checklist](PULL_REQUEST_TEMPLATE.md) with criteria for acceptable contributions.
diff --git a/aws-ec2-testing-scripts/README.md b/aws-ec2-testing-scripts/README.md
index 13f0ad6..e421c37 100644
--- a/aws-ec2-testing-scripts/README.md
+++ b/aws-ec2-testing-scripts/README.md
@@ -35,7 +35,7 @@ aws cloudformation create-stack \
ParameterKey=Tests,ParameterValue=run-eval-tests.sh
```
-When the tests are complete (either as success or failure) the email address specified in the `NotificationsEmail` parameter will receive an email notification. The email's subject will indicate if the tests were successful or failed and the email's body will contain approximately the last 200 KB of text from the Maven build log. Once you receive the notification you can terminate the stack or you can SSH into the EC2 instance if you need to debug or re-run any tests.
+When the tests are complete (either as success or failure) the email address specified in the `NotificationsEmail` parameter will receive an email notification. The email's subject will indicate if the tests were successful or failed and the email's body will contain approximately the last 200 KB of text from the Maven build log. Once you receive the notification you can terminate the stack, or you can SSH into the EC2 instance if you need to debug or re-run any tests.
```
aws cloudformation delete-stack --stack-name OpenNLP-Testing
diff --git a/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusExplorerView.java b/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusExplorerView.java
index 39f267e..a6b268c 100644
--- a/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusExplorerView.java
+++ b/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusExplorerView.java
@@ -253,7 +253,7 @@ public class CorpusExplorerView extends ViewPart {
// List with casIds in the corpus ... (might be later replaced with a title)
// The table should later be virtual, and be able to scroll through very huge
- // lits of CASes ... might be connected to a repository with million of documents
+ // lits of CASes ... might be connected to a repository with millions of documents
searchResultViewer = new TableViewer(book);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
.span(2, 1).applyTo(searchResultViewer.getControl());
diff --git a/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusServerCasEditorInput.java b/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusServerCasEditorInput.java
index 7bb64bb..53ff5f9 100644
--- a/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusServerCasEditorInput.java
+++ b/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/CorpusServerCasEditorInput.java
@@ -37,7 +37,7 @@ public class CorpusServerCasEditorInput implements IEditorInput {
return null;
}
- // can be checked through an http lookup
+ // can be checked through an HTTP lookup
@Override
public boolean exists() {
return false;
diff --git a/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java b/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java
index 33f980f..aeda502 100644
--- a/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java
+++ b/caseditor-corpus-server-plugin/src/main/java/org/apache/opennlp/corpus_server/caseditor/DefaultCasDocumentProvider.java
@@ -101,15 +101,15 @@ public class DefaultCasDocumentProvider extends
TypePriorities typePriorities = resourceSpecifierFactory
.createTypePriorities();
- FsIndexDescription indexDesciptor = new FsIndexDescription_impl();
- indexDesciptor.setLabel("TOPIndex");
- indexDesciptor.setTypeName("uima.cas.TOP");
- indexDesciptor.setKind(FsIndexDescription.KIND_SORTED);
+ FsIndexDescription indexDescriptor = new FsIndexDescription_impl();
+ indexDescriptor.setLabel("TOPIndex");
+ indexDescriptor.setTypeName("uima.cas.TOP");
+ indexDescriptor.setKind(FsIndexDescription.KIND_SORTED);
CAS cas;
try {
cas = CasCreationUtils.createCas(typeSystem, typePriorities,
- new FsIndexDescription[] { indexDesciptor });
+ new FsIndexDescription[] { indexDescriptor });
} catch (ResourceInitializationException e) {
e.printStackTrace();
cas = null;
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
index 7c0a621..31299b4 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
@@ -334,7 +334,7 @@ public class EntityContentProvider implements IStructuredContentProvider {
if (newInput != null) {
input = (ICasDocument) newInput;
- // Note: Name Finder might run to often ...
+ // Note: Name Finder might run too often ...
input.addChangeListener(casChangeListener);
input.addChangeListener(casChangeTrigger);
diff --git a/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSCasWriter.java b/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSCasWriter.java
index 5399c46..c7a93f3 100644
--- a/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSCasWriter.java
+++ b/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSCasWriter.java
@@ -115,7 +115,7 @@ public class CSCasWriter extends CasAnnotator_ImplBase {
response = casResponseBuilder.put(ClientResponse.class, xmiBytes);
}
else {
- throw new AnalysisEngineProcessException(new Exception("Unkown action: " + action));
+ throw new AnalysisEngineProcessException(new Exception("Unknown action: " + action));
}
int statusCode = response.getStatus();
diff --git a/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSQueueCollectionReader.java b/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSQueueCollectionReader.java
index 1529333..3788da1 100644
--- a/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSQueueCollectionReader.java
+++ b/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/CSQueueCollectionReader.java
@@ -103,7 +103,7 @@ public class CSQueueCollectionReader extends CollectionReader_ImplBase {
}
if (logger.isLoggable(Level.INFO)) {
- logger.log(Level.INFO, "Sucessfully created queue: " + queueName + " for corpus: " + corpusName);
+ logger.log(Level.INFO, "Successfully created queue: " + queueName + " for corpus: " + corpusName);
}
}
diff --git a/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/UimaUtil.java b/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/UimaUtil.java
index 6db5573..b606fd9 100644
--- a/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/UimaUtil.java
+++ b/corpus-server/corpus-server-connector/src/main/java/org/apache/opennlp/corpus_server/connector/UimaUtil.java
@@ -52,18 +52,18 @@ public class UimaUtil {
XMLParser xmlParser = UIMAFramework.getXMLParser();
- TypeSystemDescription typeSystemDesciptor;
+ TypeSystemDescription typeSystemDescriptor;
try {
- typeSystemDesciptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
+ typeSystemDescriptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
- typeSystemDesciptor.resolveImports();
+ typeSystemDescriptor.resolveImports();
} catch (InvalidXMLException e) {
e.printStackTrace();
- typeSystemDesciptor = null;
+ typeSystemDescriptor = null;
}
- return typeSystemDesciptor;
+ return typeSystemDescriptor;
}
public static CAS createEmptyCAS(TypeSystemDescription typeSystem) {
diff --git a/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java b/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java
index 29ecd03..57c9383 100644
--- a/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java
+++ b/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java
@@ -42,6 +42,6 @@ public class TaskQueuesResource {
public TaskQueueResource getTaskQueue(@PathParam("queue") String queueId) {
TaskQueueService taskQueueService = CorpusServerBundle.getInstance().getCorpusServer().getTaskQueueService();
- return new TaskQueueResource(taskQueueService.getTaskQeue(queueId));
+ return new TaskQueueResource(taskQueueService.getTaskQueue(queueId));
}
}
diff --git a/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java b/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
index 5eb9bd5..ff26a47 100644
--- a/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
+++ b/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
@@ -34,10 +34,9 @@ import org.apache.opennlp.corpus_server.store.CorpusStore;
*/
public class MemoryTaskQueueService implements TaskQueueService {
- private final static Logger LOGGER = Logger.getLogger(
- MemoryTaskQueueService.class .getName());
+ private final static Logger LOGGER = Logger.getLogger(MemoryTaskQueueService.class .getName());
- private Map<String, MemoryTaskQueue> queues = new HashMap<String, MemoryTaskQueue>();
+ private final Map<String, MemoryTaskQueue> queues = new HashMap<>();
@Override
public void createTaskQueue(String queueId, String corpusId, String query) {
@@ -60,7 +59,7 @@ public class MemoryTaskQueueService implements TaskQueueService {
}
@Override
- public TaskQueue getTaskQeue(String queueId) {
+ public TaskQueue getTaskQueue(String queueId) {
return queues.get(queueId);
}
}
diff --git a/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/TaskQueueService.java b/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/TaskQueueService.java
index 7f8be66..6d04d67 100644
--- a/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/TaskQueueService.java
+++ b/corpus-server/corpus-server-core/src/main/java/org/apache/opennlp/corpus_server/taskqueue/TaskQueueService.java
@@ -41,5 +41,5 @@ public interface TaskQueueService {
*
* @return the task queue or null if it does not exist
*/
- TaskQueue getTaskQeue(String queueId);
+ TaskQueue getTaskQueue(String queueId);
}
diff --git a/corpus-server/corpus-server-core/src/main/resources/org/apache/opennlp/corpus_server/search/LuceneIndexer.xml b/corpus-server/corpus-server-core/src/main/resources/org/apache/opennlp/corpus_server/search/LuceneIndexer.xml
index c96e601..3497d6e 100644
--- a/corpus-server/corpus-server-core/src/main/resources/org/apache/opennlp/corpus_server/search/LuceneIndexer.xml
+++ b/corpus-server/corpus-server-core/src/main/resources/org/apache/opennlp/corpus_server/search/LuceneIndexer.xml
@@ -66,7 +66,7 @@
<externalResources>
<externalResource>
<name>LucasIndexWriterProvider</name>
- <description>Provides a index writer instance.</description>
+ <description>Provides an index writer instance.</description>
<fileResourceSpecifier>
<fileUrl>file:src/test/resources/IndexWriter.properties</fileUrl>
</fileResourceSpecifier>
diff --git a/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneIndexer.java b/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneIndexer.java
index df5fa1e..7b6ea6e 100644
--- a/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneIndexer.java
+++ b/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneIndexer.java
@@ -42,7 +42,7 @@ import org.apache.uima.resource.ResourceInitializationException;
public class LuceneIndexer extends LuceneDocumentAE {
static final String CAS_ID_TYPE = "org.apache.opennlp.corpus_server.CasId";
- static final String CAS_ID_FEEATURE = "id";
+ static final String CAS_ID_FEATURE = "id";
private static final String RESOURCE_INDEX_WRITER_PROVIDER = "indexWriterProvider";
@@ -73,7 +73,7 @@ public class LuceneIndexer extends LuceneDocumentAE {
super.typeSystemInit(aTypeSystem);
casIdType = aTypeSystem.getType(CAS_ID_TYPE);
- casIdFeature = casIdType.getFeatureByBaseName(CAS_ID_FEEATURE);
+ casIdFeature = casIdType.getFeatureByBaseName(CAS_ID_FEATURE);
}
@Override
diff --git a/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java b/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java
index 44611ae..feae6e1 100644
--- a/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java
+++ b/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java
@@ -272,7 +272,7 @@ public class LuceneSearchService implements SearchService {
// Inject id feature structure into the CAS
Type casIdType = cas.getTypeSystem().getType(LuceneIndexer.CAS_ID_TYPE);
- Feature casIdFeature = casIdType.getFeatureByBaseName(LuceneIndexer.CAS_ID_FEEATURE);
+ Feature casIdFeature = casIdType.getFeatureByBaseName(LuceneIndexer.CAS_ID_FEATURE);
FeatureStructure casIdFS = cas.createFS(casIdType);
casIdFS.setStringValue(casIdFeature, casId);
diff --git a/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/UimaUtil.java b/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/UimaUtil.java
index 5fa8342..9d83e0d 100644
--- a/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/UimaUtil.java
+++ b/corpus-server/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/UimaUtil.java
@@ -73,15 +73,15 @@ public class UimaUtil {
TypePriorities typePriorities = resourceSpecifierFactory
.createTypePriorities();
- FsIndexDescription indexDesciptor = new FsIndexDescription_impl();
- indexDesciptor.setLabel("TOPIndex");
- indexDesciptor.setTypeName("uima.cas.TOP");
- indexDesciptor.setKind(FsIndexDescription.KIND_SORTED);
+ FsIndexDescription indexDescriptor = new FsIndexDescription_impl();
+ indexDescriptor.setLabel("TOPIndex");
+ indexDescriptor.setTypeName("uima.cas.TOP");
+ indexDescriptor.setKind(FsIndexDescription.KIND_SORTED);
CAS cas;
try {
cas = CasCreationUtils.createCas(typeSystem, typePriorities,
- new FsIndexDescription[] { indexDesciptor });
+ new FsIndexDescription[] { indexDescriptor });
} catch (ResourceInitializationException e) {
e.printStackTrace();
cas = null;
diff --git a/corpus-server/corpus-server-impl/src/main/resources/org/apache/opennlp/corpus_server/impl/LuceneIndexer.xml b/corpus-server/corpus-server-impl/src/main/resources/org/apache/opennlp/corpus_server/impl/LuceneIndexer.xml
index be7be0d..41eeae5 100644
--- a/corpus-server/corpus-server-impl/src/main/resources/org/apache/opennlp/corpus_server/impl/LuceneIndexer.xml
+++ b/corpus-server/corpus-server-impl/src/main/resources/org/apache/opennlp/corpus_server/impl/LuceneIndexer.xml
@@ -66,7 +66,7 @@
<externalResources>
<externalResource>
<name>LucasIndexWriterProvider</name>
- <description>Provides a index writer instance.</description>
+ <description>Provides an index writer instance.</description>
<fileResourceSpecifier>
<fileUrl>file:src/test/resources/IndexWriter.properties</fileUrl>
</fileResourceSpecifier>
diff --git a/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CorpusBackup.java b/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CorpusBackup.java
index 53d9ddd..73c35d6 100644
--- a/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CorpusBackup.java
+++ b/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CorpusBackup.java
@@ -33,15 +33,16 @@ import com.sun.jersey.api.client.WebResource;
/**
* Tools to back up a corpus from the corpus server into a zip package.
- *
- * Sample server address: http://localhost:8080/corpus-server/rest
+ * <p>
+ * Sample server address:
+ * <a href="http://localhost:8080/corpus-server/rest">http://localhost:8080/corpus-server/rest</a>.
*/
public class CorpusBackup {
private static void copyStream(InputStream in,
OutputStream out) throws IOException {
- byte buffer[] = new byte[1024];
+ byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
@@ -129,19 +130,10 @@ public class CorpusBackup {
.get(ClientResponse.class);
zipPackageOut.putNextEntry(new ZipEntry(casId));
-
- InputStream casIn = casResponse.getEntityInputStream();
-
- try {
+
+ try (InputStream casIn = casResponse.getEntityInputStream()) {
copyStream(casIn, zipPackageOut);
}
- finally {
- try {
- casIn.close();
- }
- catch (IOException e) {
- }
- }
zipPackageOut.closeEntry();
diff --git a/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CreateCorpus.java b/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CreateCorpus.java
index 45d4f51..ebcea1d 100644
--- a/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CreateCorpus.java
+++ b/corpus-server/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/CreateCorpus.java
@@ -68,17 +68,17 @@ public class CreateCorpus {
XMLParser xmlParser = UIMAFramework.getXMLParser();
- TypeSystemDescription typeSystemDesciptor = (TypeSystemDescription) xmlParser
+ TypeSystemDescription typeSystemDescriptor = (TypeSystemDescription) xmlParser
.parse(xmlTypeSystemSource);
- typeSystemDesciptor.resolveImports();
+ typeSystemDescriptor.resolveImports();
ByteArrayOutputStream typeSystemBytes = new ByteArrayOutputStream();
- typeSystemDesciptor.toXML(typeSystemBytes);
+ typeSystemDescriptor.toXML(typeSystemBytes);
resources[0] = typeSystemBytes.toByteArray();
- byte indexMappingBytes[] = FileUtil.fileToBytes(new File(args[3]));
+ byte[] indexMappingBytes = FileUtil.fileToBytes(new File(args[3]));
resources[1] = indexMappingBytes;
ClientResponse response = r.path("_createCorpus")
diff --git a/mallet-addon/src/main/java/opennlp/addons/mallet/ClassifierModel.java b/mallet-addon/src/main/java/opennlp/addons/mallet/ClassifierModel.java
index 1426be9..ce5df95 100644
--- a/mallet-addon/src/main/java/opennlp/addons/mallet/ClassifierModel.java
+++ b/mallet-addon/src/main/java/opennlp/addons/mallet/ClassifierModel.java
@@ -37,8 +37,8 @@ class ClassifierModel implements MaxentModel, SerializableArtifact {
private final Classifier classifier;
- public ClassifierModel(Classifier classifer) {
- this.classifier = classifer;
+ public ClassifierModel(Classifier classifier) {
+ this.classifier = classifier;
}
Classifier getClassifier() {
@@ -58,7 +58,7 @@ class ClassifierModel implements MaxentModel, SerializableArtifact {
}
}
- int malletFeatures[] = new int[malletFeatureList.size()];
+ int[] malletFeatures = new int[malletFeatureList.size()];
for (int i = 0; i < malletFeatureList.size(); i++) {
malletFeatures[i] = malletFeatureList.get(i);
}
@@ -73,7 +73,7 @@ class ClassifierModel implements MaxentModel, SerializableArtifact {
LabelAlphabet targetAlphabet = classifier.getLabelAlphabet();
- double outcomes[] = new double[targetAlphabet.size()];
+ double[] outcomes = new double[targetAlphabet.size()];
for (int i = 0; i < outcomes.length; i++) {
Label label = targetAlphabet.lookupLabel(i);
diff --git a/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/DefaultModelBuilderUtil.java b/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/DefaultModelBuilderUtil.java
index cd73202..f100a96 100644
--- a/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/DefaultModelBuilderUtil.java
+++ b/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/DefaultModelBuilderUtil.java
@@ -81,7 +81,7 @@ public class DefaultModelBuilderUtil {
/*
* KnownEntityProviders provide a seed list of known entities... such as
* Barack Obama for person, or Germany for location obviously these would
- * want to be prolific, non ambiguous names
+ * want to be prolific, non-ambiguous names
*/
KnownEntityProvider knownEntityProvider = new FileKnownEntityProvider();
knownEntityProvider.setParameters(params);
diff --git a/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/KnownEntityProvider.java b/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/KnownEntityProvider.java
index 39f5e5d..a905f02 100644
--- a/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/KnownEntityProvider.java
+++ b/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/KnownEntityProvider.java
@@ -21,20 +21,21 @@ import java.util.Set;
* Supplies a list of known entities (a list of names or locations)
*/
public interface KnownEntityProvider extends ModelParameter {
+
/**
- * returns a list of known non ambiguous entities.
+ * Returns a list of known non-ambiguous entities.
* @return a set of entities
*/
Set<String> getKnownEntities();
/**
- * adds to the set of known entities. Overriding classes should hold this list in a class level set.
+ * Adds to the set of known entities. Overriding classes should hold this list in a class level set.
* @param unambiguousEntity
*/
void addKnownEntity(String unambiguousEntity);
/**
- * defines the type of entity that the set contains, ie person, location, organization.
+ * Defines the type of entity that the set contains, ie person, location, organization.
* @return
*/
String getKnownEntitiesType();
diff --git a/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/Modelable.java b/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/Modelable.java
index 2fdcce8..2f78254 100644
--- a/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/Modelable.java
+++ b/modelbuilder-addon/src/main/java/opennlp/addons/modelbuilder/Modelable.java
@@ -18,9 +18,7 @@ package opennlp.addons.modelbuilder;
import java.util.Set;
import opennlp.tools.namefind.TokenNameFinderModel;
-/**
- *
- */
+
public interface Modelable extends ModelParameter {
String annotate(String sentence, String namedEntity, String entityType);
diff --git a/nlp-utils/src/main/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifier.java b/nlp-utils/src/main/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifier.java
index 1114677..ca60ce5 100644
--- a/nlp-utils/src/main/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifier.java
+++ b/nlp-utils/src/main/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifier.java
@@ -42,7 +42,7 @@ public class SimpleNaiveBayesClassifier implements NaiveBayesClassifier<String,
private static final String UNKNOWN_WORD_TOKEN = "_unk_word_";
private Collection<String> vocabulary; // the bag of all the words in the corpus
- private final Map<String, String> docsWithClass; // this is the trained corpus holding a the doc as a key and the class as a value
+ private final Map<String, String> docsWithClass; // this is the trained corpus holding the doc as a key and the class as a value
private Map<String, String> classMegaDocMap; // key is the class, value is the megadoc
// private Map<String, String> preComputedWordClasses; // the key is the word, the value is its likelihood
private Map<String, Double> priors;
diff --git a/nlp-utils/src/main/java/org/apache/opennlp/utils/languagemodel/NoisyChannel.java b/nlp-utils/src/main/java/org/apache/opennlp/utils/languagemodel/NoisyChannel.java
index 9085605..9ea1aab 100644
--- a/nlp-utils/src/main/java/org/apache/opennlp/utils/languagemodel/NoisyChannel.java
+++ b/nlp-utils/src/main/java/org/apache/opennlp/utils/languagemodel/NoisyChannel.java
@@ -29,11 +29,11 @@ public abstract class NoisyChannel {
this.dictionary = dictionary;
}
- public String findCorrection(String mispelledWord) {
+ public String findCorrection(String misspelledWord) {
double val = 0d;
String correctWord = null;
for (String word : dictionary) {
- double curVal = calculateLikelihood(mispelledWord, word) * calculatePrior(word);
+ double curVal = calculateLikelihood(misspelledWord, word) * calculatePrior(word);
if (curVal > val) {
val = curVal;
correctWord = word;
diff --git a/nlp-utils/src/main/java/org/apache/opennlp/utils/regression/RegressionModelUtils.java b/nlp-utils/src/main/java/org/apache/opennlp/utils/regression/RegressionModelUtils.java
index 7b606a2..5987620 100644
--- a/nlp-utils/src/main/java/org/apache/opennlp/utils/regression/RegressionModelUtils.java
+++ b/nlp-utils/src/main/java/org/apache/opennlp/utils/regression/RegressionModelUtils.java
@@ -64,7 +64,7 @@ public class RegressionModelUtils {
}
/**
- * calculate least mean square update for a given training example for the j-th input
+ * Calculates the Least Mean Square update for a given training example for the j-th input.
*
* @param thetas The array of weights.
* @param alpha The learning rate alpha.
diff --git a/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java b/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java
index 9ad4276..a634c10 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/CoreferencerTool.java
@@ -46,7 +46,7 @@ import opennlp.tools.util.Span;
public class CoreferencerTool extends BasicCmdLineTool {
- class CorefParse {
+ static class CorefParse {
private final Map<Parse, Integer> parseMap;
private final List<Parse> parses;
@@ -135,7 +135,7 @@ public class CoreferencerTool extends BasicCmdLineTool {
DiscourseEntity[] entities =
treebankLinker.getEntities(document.toArray(new Mention[document.size()]));
//showEntities(entities);
- new CorefParse(parses,entities).show();
+ new CorefParse(parses, entities).show();
sentenceNumber = 0;
document.clear();
parses.clear();
@@ -150,7 +150,7 @@ public class CoreferencerTool extends BasicCmdLineTool {
//System.err.println("PennTreebankLiner.main: "+ei+" "+extents[ei]);
if (extent.getParse() == null) {
- //not sure how to get head index, but its not used at this point.
+ //not sure how to get head index, but it's not used at this point.
Parse snp = new Parse(p.getText(), extent.getSpan(), "NML", 1.0, 0);
p.insert(snp);
extent.setParse(new DefaultParse(snp, sentenceNumber));
diff --git a/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/TrainingParams.java b/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/TrainingParams.java
index 9509cec..d534d70 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/TrainingParams.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/cmdline/coref/TrainingParams.java
@@ -21,7 +21,7 @@ import opennlp.tools.cmdline.params.BasicTrainingParams;
/**
* TrainingParameters for Name Finder.
- *
+ * <p>
* Note: Do not use this class, internal use only!
*/
interface TrainingParams extends BasicTrainingParams {
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/AbstractLinker.java b/opennlp-coref/src/main/java/opennlp/tools/coref/AbstractLinker.java
index 38af1f7..f34953c 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/AbstractLinker.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/AbstractLinker.java
@@ -43,7 +43,7 @@ public abstract class AbstractLinker implements Linker {
/** The mode in which this linker is running. */
protected LinkerMode mode;
- /** Instance used for for returning the same linker for subsequent getInstance requests. */
+ /** Instance used for returning the same linker for subsequent getInstance requests. */
protected static Linker linker;
/** The resolvers used by this Linker. */
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/Linker.java b/opennlp-coref/src/main/java/opennlp/tools/coref/Linker.java
index 263b1b1..78c7ceb 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/Linker.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/Linker.java
@@ -38,32 +38,32 @@ public interface Linker {
/**
* String constant used to label a mention which is a description.
*/
- public static final String DESCRIPTOR = "desc";
+ String DESCRIPTOR = "desc";
/**
- * String constant used to label an mention in an appositive relationship.
+ * String constant used to label a mention in an appositive relationship.
*/
- public static final String ISA = "isa";
+ String ISA = "isa";
/**
* String constant used to label a mention which consists of two or more noun phrases.
*/
- public static final String COMBINED_NPS = "cmbnd";
+ String COMBINED_NPS = "cmbnd";
/**
* String constant used to label a mention which consists of a single noun phrase.
*/
- public static final String NP = "np";
+ String NP = "np";
/**
* String constant used to label a mention which is a proper noun modifying another noun.
*/
- public static final String PROPER_NOUN_MODIFIER = "pnmod";
+ String PROPER_NOUN_MODIFIER = "pnmod";
/**
* String constant used to label a mention which is a pronoun.
*/
- public static final String PRONOUN_MODIFIER = "np";
+ String PRONOUN_MODIFIER = "np";
/**
@@ -73,14 +73,15 @@ public interface Linker {
*
* @param mentions The mentions to be used to train the linker.
*/
- public void setEntities(Mention[] mentions);
+ void setEntities(Mention[] mentions);
- /** Returns a list of entities which group the mentions into entity classes.
- * @param mentions A array of mentions.
+ /**
+ * Returns a list of entities which group the mentions into entity classes.
+ * @param mentions An array of mentions.
*
* @return An array of discourse entities.
*/
- public DiscourseEntity[] getEntities(Mention[] mentions);
+ DiscourseEntity[] getEntities(Mention[] mentions);
/**
* Creates mention contexts for the specified mention exents.
@@ -90,26 +91,27 @@ public interface Linker {
*
* @return mention contexts for the specified mention exents.
*/
- public MentionContext[] constructMentionContexts(Mention[] mentions);
+ MentionContext[] constructMentionContexts(Mention[] mentions);
/**
- * Trains the linker based on the data specified via calls to {@link #setEntities setEntities}.
+ * Trains the linker based on the data specified via calls to {@link #setEntities}.
*
- * @throws IOException
+ * @throws IOException Thrown if IO errors occurred.
*/
- public void train() throws IOException;
+ void train() throws IOException;
/**
- * Returns the mention finder for this linker. This can be used to get the mentions of a Parse.
+ * Returns the mention finder for this linker.
+ * This can be used to get the mentions of a Parse.
*
* @return The object which finds mentions for this linker.
*/
- public MentionFinder getMentionFinder();
+ MentionFinder getMentionFinder();
/**
* Returns the head finder associated with this linker.
*
* @return The head finder associated with this linker.
*/
- public HeadFinder getHeadFinder();
+ HeadFinder getHeadFinder();
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/LinkerMode.java b/opennlp-coref/src/main/java/opennlp/tools/coref/LinkerMode.java
index 654db5a..5e4284d 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/LinkerMode.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/LinkerMode.java
@@ -33,7 +33,7 @@ public enum LinkerMode {
*/
TRAIN,
- /** Evaluation mode, used to evaluate identifed coreference relationships based on annotated text. */
+ /** Evaluation mode, used to evaluate identified coreference relationships based on annotated text. */
EVAL,
/**
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractMentionFinder.java b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractMentionFinder.java
index 8d50266..20a853e 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractMentionFinder.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractMentionFinder.java
@@ -320,7 +320,7 @@ public abstract class AbstractMentionFinder implements MentionFinder {
return mentions.toArray(new Mention[mentions.size()]);
}
- /**
+ /*
* Adds a mention for the non-treebank-labeled possesive noun phrases.
* @param possesiveNounPhrase The possesive noun phase which may require an additional mention.
* @param mentions The list of mentions into which a new mention can be added.
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractParse.java b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractParse.java
index 71b9bb1..de43806 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractParse.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/AbstractParse.java
@@ -21,10 +21,11 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Provides default implemenation of many of the methods in the {@link Parse} interface.
+ * Provides default implementation of many of the methods in the {@link Parse} interface.
*/
public abstract class AbstractParse implements Parse {
+ @Override
public boolean isCoordinatedNounPhrase() {
List<Parse> parts = getSyntacticChildren();
if (parts.size() >= 2) {
@@ -39,14 +40,14 @@ public abstract class AbstractParse implements Parse {
return false;
}
+ @Override
public List<Parse> getNounPhrases() {
List<Parse> parts = getSyntacticChildren();
List<Parse> nps = new ArrayList<>();
while (parts.size() > 0) {
List<Parse> newParts = new ArrayList<>();
- for (int pi = 0, pn = parts.size(); pi < pn;pi++) {
+ for (Parse cp : parts) {
//System.err.println("AbstractParse.getNounPhrases "+parts.get(pi).getClass());
- Parse cp = parts.get(pi);
if (cp.isNounPhrase()) {
nps.add(cp);
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/HeadFinder.java b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/HeadFinder.java
index b378ef9..5820c68 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/HeadFinder.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/HeadFinder.java
@@ -26,10 +26,10 @@ public interface HeadFinder {
* Returns the child parse which contains the lexical head of the specified parse.
*
* @param parse The parse in which to find the head.
- * @return The parse containing the lexical head of the specified parse. If no head is
- * available or the constituent has no sub-components that are eligible heads then null is returned.
+ * @return The parse containing the lexical head of the specified parse. If no head is
+ * available or the constituent has no subcomponents that are eligible heads then null is returned.
*/
- public Parse getHead(Parse parse);
+ Parse getHead(Parse parse);
/**
* Returns which index the specified list of token is the head word.
@@ -37,7 +37,7 @@ public interface HeadFinder {
* @param parse The parse in which to find the head index.
* @return The index of the head token.
*/
- public int getHeadIndex(Parse parse);
+ int getHeadIndex(Parse parse);
/**
* Returns the parse bottom-most head of a <code>Parse</code>. If no
@@ -46,7 +46,7 @@ public interface HeadFinder {
* @param p Parse to find the head of.
* @return bottom-most head of p.
*/
- public Parse getLastHead(Parse p);
+ Parse getLastHead(Parse p);
/**
* Returns head token for the specified np parse.
@@ -54,5 +54,5 @@ public interface HeadFinder {
* @param np The noun parse to get head from.
* @return head token parse.
*/
- public Parse getHeadToken(Parse np);
+ Parse getHeadToken(Parse np);
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Mention.java b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Mention.java
index 25259e7..2308220 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Mention.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Mention.java
@@ -27,7 +27,7 @@ public class Mention implements Comparable<Mention> {
/**
* Represents the character offset for this extent.
*/
- private Span span;
+ private final Span span;
/**
* A string representing the type of this extent. This is helpful for determining
@@ -42,9 +42,9 @@ public class Mention implements Comparable<Mention> {
private int id;
/**
- * Represents the character offsets of the the head of this extent.
+ * Represents the character offsets of the head of this extent.
*/
- private Span headSpan;
+ private final Span headSpan;
/**
* The parse node that this extent is based on.
@@ -104,6 +104,7 @@ public class Mention implements Comparable<Mention> {
return parse;
}
+ @Override
public int compareTo(Mention e) {
return span.compareTo(e.span);
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/MentionContext.java b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/MentionContext.java
index 059910b..0986557 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/MentionContext.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/MentionContext.java
@@ -161,7 +161,7 @@ public class MentionContext extends Context {
}
- /**
+ /*
* Constructs context information for the specified mention.
*
* @param mentionParse Mention parse structure for which context is to be constructed.
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/PTBMentionFinder.java b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/PTBMentionFinder.java
index c51e336..4793024 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/PTBMentionFinder.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/PTBMentionFinder.java
@@ -83,10 +83,11 @@ public class PTBMentionFinder extends AbstractMentionFinder {
}
*/
- /** Moves entity ids assigned to basal nps and possesives to their
- * maximaly containing np. Also assign head information of basal
+ /*
+ * Moves entity ids assigned to basal nps and possessives to their
+ * maximally containing np. Also assign head information of basal
* noun phase to the maximally containing np.
- * @deprecated No on uses this any more.
+ * @deprecated No on uses this anymore.
*
private void propigateEntityIds(Map headMap) {
for (Iterator ki = headMap.keySet().iterator(); ki.hasNext();) {
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Parse.java b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Parse.java
index 6cc07ad..c0b6c81 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Parse.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/mention/Parse.java
@@ -32,7 +32,7 @@ public interface Parse extends Comparable<Parse> {
*
* @return The index of the sentence which contains this parse.
*/
- public int getSentenceNumber();
+ int getSentenceNumber();
/**
* Returns a list of the all noun phrases
@@ -41,7 +41,7 @@ public interface Parse extends Comparable<Parse> {
*
* @return a list of all the noun phrases contained by this parse.
*/
- public List<Parse> getNounPhrases();
+ List<Parse> getNounPhrases();
/**
* Returns a list of all the named entities
@@ -49,25 +49,25 @@ public interface Parse extends Comparable<Parse> {
* also implement the {@link Parse} interface.
*
* @return a list of all the named entities contained by this parse. */
- public List<Parse> getNamedEntities();
+ List<Parse> getNamedEntities();
/**
- * Returns a list of the children to this object. The
+ * Returns a list of the children to this object. The
* children should also implement the {@link Parse} interface
* .
* @return a list of the children to this object.
* */
- public List<Parse> getChildren();
+ List<Parse> getChildren();
/**
* Returns a list of the children to this object which are constituents or tokens. The
- * children should also implement the {@link Parse} interface. This allows
+ * children should also implement the {@link Parse} interface. This allows
* implementations which contain addition nodes for things such as semantic categories to
* hide those nodes from the components which only care about syntactic nodes.
*
* @return a list of the children to this object which are constituents or tokens.
*/
- public List<Parse> getSyntacticChildren();
+ List<Parse> getSyntacticChildren();
/**
* Returns a list of the tokens contained by this object. The tokens in this list should also
@@ -75,102 +75,102 @@ public interface Parse extends Comparable<Parse> {
*
* @return the tokens
*/
- public List<Parse> getTokens();
+ List<Parse> getTokens();
/**
- * Returns the syntactic type of this node. Typically this is the part-of-speech or
+ * Returns the syntactic type of this node. Typically, this is the part-of-speech or
* constituent labeling.
*
* @return the syntactic type.
*/
- public String getSyntacticType();
+ String getSyntacticType();
/**
* Returns the named-entity type of this node.
*
* @return the named-entity type.
*/
- public String getEntityType();
+ String getEntityType();
/**
* Determines whether this has an ancestor of type NAC.
*
- * @return true is this has an ancestor of type NAC, false otherwise.
+ * @return {@code True} if this has an ancestor of type NAC, {@code false} otherwise.
*/
- public boolean isParentNAC();
+ boolean isParentNAC();
/**
* Returns the parent parse of this parse node.
*
* @return the parent parse of this parse node.
*/
- public Parse getParent();
+ Parse getParent();
/**
* Specifies whether this parse is a named-entity.
*
- * @return True if this parse is a named-entity; false otherwise.
+ * @return {@code True} if this parse is a named-entity; {@code false} otherwise.
*/
- public boolean isNamedEntity();
+ boolean isNamedEntity();
/**
* Specifies whether this parse is a noun phrase.
*
- * @return True if this parse is a noun phrase; false otherwise.
+ * @return {@code True} if this parse is a noun phrase; {@code false} otherwise.
*/
- public boolean isNounPhrase();
+ boolean isNounPhrase();
/**
* Specifies whether this parse is a sentence.
*
- * @return True if this parse is a sentence; false otherwise.
+ * @return {@code True} if this parse is a sentence; {@code false} otherwise.
*/
- public boolean isSentence();
+ boolean isSentence();
/**
* Specifies whether this parse is a coordinated noun phrase.
*
- * @return True if this parse is a coordinated noun phrase; false otherwise.
+ * @return {@code True} if this parse is a coordinated noun phrase; {@code false} otherwise.
*/
- public boolean isCoordinatedNounPhrase();
+ boolean isCoordinatedNounPhrase();
/**
* Specifies whether this parse is a token.
*
- * @return True if this parse is a token; false otherwise.
+ * @return {@code True} if this parse is a token; {@code false} otherwise.
*/
- public boolean isToken();
+ boolean isToken();
- public String toString();
+ String toString();
/**
- * Returns an entity id associated with this parse and coreferent parses. This is only used for training on
+ * Returns an entity id associated with this parse and co-referent parses. This is only used for training on
* already annotated coreference annotation.
*
- * @return an entity id associated with this parse and coreferent parses.
+ * @return an entity id associated with this parse and co-referent parses.
*/
- public int getEntityId();
+ int getEntityId();
/**
* Returns the character offsets of this parse node.
*
* @return The span representing the character offsets of this parse node.
*/
- public Span getSpan();
+ Span getSpan();
/**
- * Returns the first token which is not a child of this parse. If the first token of a sentence is
+ * Returns the first token which is not a child of this parse. If the first token of a sentence is
* a child of this parse then null is returned.
*
* @return the first token which is not a child of this parse or null if no such token exists.
*/
- public Parse getPreviousToken();
+ Parse getPreviousToken();
/**
- * Returns the next token which is not a child of this parse. If the last token of a sentence is
+ * Returns the next token which is not a child of this parse. If the last token of a sentence is
* a child of this parse then null is returned.
*
* @return the next token which is not a child of this parse or null if no such token exists.
*/
- public Parse getNextToken();
+ Parse getNextToken();
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/CommonNounResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/CommonNounResolver.java
index 9ee64b6..5cd8a9d 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/CommonNounResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/CommonNounResolver.java
@@ -44,8 +44,7 @@ public class CommonNounResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention, entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
if (entity != null) {
features.addAll(ResolverUtils.getContextFeatures(mention));
features.addAll(ResolverUtils.getStringMatchFeatures(mention,entity));
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/DefiniteNounResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/DefiniteNounResolver.java
index f9921e6..5a95332 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/DefiniteNounResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/DefiniteNounResolver.java
@@ -55,8 +55,7 @@ public class DefiniteNounResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention, entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
if (entity != null) {
features.addAll(ResolverUtils.getContextFeatures(mention));
features.addAll(ResolverUtils.getStringMatchFeatures(mention,entity));
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/IsAResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/IsAResolver.java
index 412e00f..70778ec 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/IsAResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/IsAResolver.java
@@ -98,8 +98,7 @@ public class IsAResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention, entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
if (entity != null) {
MentionContext ant = entity.getLastExtent();
List<String> leftContexts = ResolverUtils.getContextFeatures(ant);
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/NonReferentialResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/NonReferentialResolver.java
index d042188..d365a85 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/NonReferentialResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/NonReferentialResolver.java
@@ -22,7 +22,7 @@ import java.io.IOException;
import opennlp.tools.coref.mention.MentionContext;
/**
- * Provides the interface for a object to provide a resolver with a non-referential
+ * Provides the interface for an object to provide a resolver with a non-referential
* probability. Non-referential resolvers compute the probability that a particular mention refers
* to no antecedent. This probability can then compete with the probability that
* a mention refers with a specific antecedent.
@@ -35,7 +35,7 @@ public interface NonReferentialResolver {
* @param mention The mention under consideration.
* @return A probability that the specified mention doesn't refer to any previous mention.
*/
- public double getNonReferentialProbability(MentionContext mention);
+ double getNonReferentialProbability(MentionContext mention);
/**
* Designates that the specified mention be used for training.
@@ -43,12 +43,12 @@ public interface NonReferentialResolver {
* @param mention The mention to be used. The mention id is used to determine
* whether this mention is referential or non-referential.
*/
- public void addEvent(MentionContext mention);
+ void addEvent(MentionContext mention);
/**
* Trains a model based on the events given to this resolver via #addEvent.
*
* @throws IOException When the model can not be written out.
*/
- public void train() throws IOException;
+ void train() throws IOException;
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralNounResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralNounResolver.java
index d7a9761..0a8c2a5 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralNounResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralNounResolver.java
@@ -44,8 +44,7 @@ public class PluralNounResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention, entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
if (entity != null) {
features.addAll(ResolverUtils.getContextFeatures(mention));
features.addAll(ResolverUtils.getStringMatchFeatures(mention,entity));
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralPronounResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralPronounResolver.java
index 345f118..72f43fb 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralPronounResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/PluralPronounResolver.java
@@ -42,8 +42,7 @@ public class PluralPronounResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention,entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
//features.add("eid="+pc.id);
if (entity != null) { //generate pronoun w/ referent features
features.addAll(ResolverUtils.getPronounMatchFeatures(mention,entity));
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ProperNounResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ProperNounResolver.java
index 0e6070c..1df4743 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ProperNounResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ProperNounResolver.java
@@ -119,8 +119,7 @@ public class ProperNounResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
//System.err.println("ProperNounResolver.getFeatures: "+mention.toText()+" -> "+entity);
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention, entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
if (entity != null) {
features.addAll(ResolverUtils.getStringMatchFeatures(mention, entity));
features.addAll(getAcronymFeatures(mention, entity));
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/Resolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/Resolver.java
index f237c7e..f2b891d 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/Resolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/Resolver.java
@@ -37,7 +37,7 @@ public interface Resolver {
* @return true if the resolver handles this type of referring
* expression, false otherwise.
*/
- public boolean canResolve(MentionContext mention);
+ boolean canResolve(MentionContext mention);
/**
* Resolve this referring expression to a discourse entity in the discourse model.
@@ -47,9 +47,9 @@ public interface Resolver {
*
* @return the discourse entity which the resolver believes this
* referring expression refers to or null if no discourse entity is
- * coreferent with the referring expression.
+ * co-referent with the referring expression.
*/
- public DiscourseEntity resolve(MentionContext ec, DiscourseModel dm);
+ DiscourseEntity resolve(MentionContext ec, DiscourseModel dm);
/**
* Uses the specified mention and discourse model to train this resolver.
@@ -62,12 +62,12 @@ public interface Resolver {
* @return the discourse entity which is referred to by the referring
* expression or null if no discourse entity is referenced.
*/
- public DiscourseEntity retain(MentionContext mention, DiscourseModel model);
+ DiscourseEntity retain(MentionContext mention, DiscourseModel model);
/**
* Retrains model on examples for which retain was called.
*
* @throws IOException
*/
- public void train() throws IOException;
+ void train() throws IOException;
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ResolverUtils.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ResolverUtils.java
index 676b6de..1e5539b 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ResolverUtils.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/ResolverUtils.java
@@ -41,10 +41,10 @@ public class ResolverUtils {
private static final Pattern ENDS_WITH_PERIOD = Pattern.compile("\\.$");
private static final Pattern initialCaps = Pattern.compile("^[A-Z]");
- /** Regular expression for English singular third person pronouns. */
+ /** Regular expression for English singular third-person pronouns. */
public static final Pattern singularThirdPersonPronounPattern =
Pattern.compile("^(he|she|it|him|her|his|hers|its|himself|herself|itself)$",Pattern.CASE_INSENSITIVE);
- /** Regular expression for English plural third person pronouns. */
+ /** Regular expression for English plural third-person pronouns. */
public static final Pattern pluralThirdPersonPronounPattern =
Pattern.compile("^(they|their|theirs|them|themselves)$",Pattern.CASE_INSENSITIVE);
/** Regular expression for English speech pronouns. */
@@ -56,13 +56,13 @@ public class ResolverUtils {
/** Regular expression for English neuter pronouns. */
public static final Pattern neuterPronounPattern =
Pattern.compile("^(it|its|itself)$",Pattern.CASE_INSENSITIVE);
- /** Regular expression for English first person pronouns. */
+ /** Regular expression for English first-person pronouns. */
public static final Pattern firstPersonPronounPattern =
Pattern.compile("^(I|me|my|we|our|us|ours)$",Pattern.CASE_INSENSITIVE);
- /** Regular expression for English singular second person pronouns. */
+ /** Regular expression for English singular second-person pronouns. */
public static final Pattern secondPersonPronounPattern =
Pattern.compile("^(you|your|yours)$",Pattern.CASE_INSENSITIVE);
- /** Regular expression for English third person pronouns. */
+ /** Regular expression for English third-person pronouns. */
public static final Pattern thirdPersonPronounPattern =
Pattern.compile("^(he|she|it|him|her|his|hers|its|himself|herself|itself|they|" +
"their|theirs|them|themselves)$",Pattern.CASE_INSENSITIVE);
@@ -103,11 +103,11 @@ public class ResolverUtils {
/**
* Returns a list of features based on the surrounding context of the specified mention.
- * @param mention he mention whose surround context the features model.
+ * @param mention The mention whose surround context the features model.
* @return a list of features based on the surrounding context of the specified mention
*/
public static List<String> getContextFeatures(MentionContext mention) {
- List<String> features = new ArrayList<String>();
+ List<String> features = new ArrayList<>();
if (mention.getPreviousToken() != null) {
features.add("pt=" + mention.getPreviousToken().getSyntacticType());
features.add("pw=" + mention.getPreviousToken().toString());
@@ -141,7 +141,7 @@ public class ResolverUtils {
* @return a list of word features for the specified tokens.
*/
public static List<String> getWordFeatures(Parse token) {
- List<String> wordFeatures = new ArrayList<String>();
+ List<String> wordFeatures = new ArrayList<>();
String word = token.toString().toLowerCase();
String wf = "";
if (ENDS_WITH_PERIOD.matcher(word).find()) {
@@ -154,7 +154,7 @@ public class ResolverUtils {
}
public static Set<String> constructModifierSet(Parse[] tokens, int headIndex) {
- Set<String> modSet = new HashSet<String>();
+ Set<String> modSet = new HashSet<>();
for (int ti = 0; ti < headIndex; ti++) {
Parse tok = tokens[ti];
modSet.add(tok.toString().toLowerCase());
@@ -166,8 +166,7 @@ public class ResolverUtils {
StringBuilder sb = new StringBuilder();
boolean first = true;
Parse[] mtokens = ec.getTokenParses();
- for (int ti = 0, tl = mtokens.length; ti < tl; ti++) {
- Parse token = mtokens[ti];
+ for (Parse token : mtokens) {
String tag = token.getSyntacticType();
if (!tag.equals("DT")) {
if (!first) {
@@ -184,8 +183,8 @@ public class ResolverUtils {
StringBuilder sb = new StringBuilder();
boolean first = true;
Object[] mtokens = ec.getTokens();
- for (int ti = 0, tl = mtokens.length; ti < tl; ti++) {
- String token = mtokens[ti].toString();
+ for (Object mtoken : mtokens) {
+ String token = mtoken.toString();
if (!honorificsPattern.matcher(token).matches()) {
if (!first) {
sb.append(" ");
@@ -201,8 +200,8 @@ public class ResolverUtils {
StringBuilder sb = new StringBuilder();
boolean first = true;
Object[] mtokens = ec.getTokens();
- for (int ti = 0, tl = mtokens.length; ti < tl; ti++) {
- String token = mtokens[ti].toString();
+ for (Object mtoken : mtokens) {
+ String token = mtoken.toString();
if (!token.equals("the") && !token.equals("The") && !token.equals("THE")) {
if (!first) {
sb.append(" ");
@@ -232,21 +231,21 @@ public class ResolverUtils {
}
/**
- * Returns string-match features for the the specified mention and entity.
+ * Returns string-match features for the specified mention and entity.
* @param mention The mention.
* @param entity The entity.
- * @return list of string-match features for the the specified mention and entity.
+ * @return list of string-match features for the specified mention and entity.
*/
public static List<String> getStringMatchFeatures(MentionContext mention, DiscourseEntity entity) {
boolean sameHead = false;
boolean modsMatch = false;
boolean titleMatch = false;
boolean nonTheModsMatch = false;
- List<String> features = new ArrayList<String>();
+ List<String> features = new ArrayList<>();
Parse[] mtokens = mention.getTokenParses();
Set<String> ecModSet = constructModifierSet(mtokens, mention.getHeadTokenIndex());
String mentionHeadString = mention.getHeadTokenText().toLowerCase();
- Set<String> featureSet = new HashSet<String>();
+ Set<String> featureSet = new HashSet<>();
for (Iterator<MentionContext> ei = entity.getMentions(); ei.hasNext();) {
MentionContext entityMention = ei.next();
String exactMatchFeature = getExactMatchFeature(entityMention, mention);
@@ -282,8 +281,7 @@ public class ResolverUtils {
modsMatch = true;
nonTheModsMatch = true;
Set<String> entityMentionModifierSet = constructModifierSet(xtoks, headIndex);
- for (Iterator<String> mi = ecModSet.iterator(); mi.hasNext();) {
- String mw = mi.next();
+ for (String mw : ecModSet) {
if (!entityMentionModifierSet.contains(mw)) {
modsMatch = false;
if (!mw.equals("the")) {
@@ -405,15 +403,15 @@ public class ResolverUtils {
//System.err.println("stripNp: return null 5");
return null;
}
- String strip = "";
+ StringBuilder strip = new StringBuilder();
for (int i = start; i < end; i++) {
- strip += mtokens[i].toString() + ' ';
+ strip.append(mtokens[i].toString()).append(' ');
}
- return strip.trim();
+ return strip.toString().trim();
}
public static MentionContext getProperNounExtent(DiscourseEntity de) {
- //use first extent which is propername
+ //use first extent which is proper name
for (Iterator<MentionContext> ei = de.getMentions(); ei.hasNext();) {
MentionContext xec = ei.next();
String xecHeadTag = xec.getHeadTokenTag();
@@ -425,7 +423,7 @@ public class ResolverUtils {
}
private static Map<String, String> getPronounFeatureMap(String pronoun) {
- Map<String, String> pronounMap = new HashMap<String, String>();
+ Map<String, String> pronounMap = new HashMap<>();
if (malePronounPattern.matcher(pronoun).matches()) {
pronounMap.put("gender","male");
}
@@ -481,16 +479,14 @@ public class ResolverUtils {
getPronounFeatureMap(candidateMention.getHeadTokenText());
//System.err.println("getPronounMatchFeatures.candidatePronounMap:"+candidatePronounMap);
boolean allKeysMatch = true;
- for (Iterator<String> ki = pronounMap.keySet().iterator(); ki.hasNext();) {
- String key = ki.next();
+ for (String key : pronounMap.keySet()) {
String cfv = candidatePronounMap.get(key);
if (cfv != null) {
if (!pronounMap.get(key).equals(cfv)) {
foundIncompatiblePronoun = true;
allKeysMatch = false;
}
- }
- else {
+ } else {
allKeysMatch = false;
}
}
@@ -518,7 +514,7 @@ public class ResolverUtils {
* @return list of distance features for the specified mention and entity.
*/
public static List<String> getDistanceFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
+ List<String> features = new ArrayList<>();
MentionContext cec = entity.getLastExtent();
int entityDistance = mention.getNounPhraseDocumentIndex() - cec.getNounPhraseDocumentIndex();
int sentenceDistance = mention.getSentenceNumber() - cec.getSentenceNumber();
@@ -581,7 +577,7 @@ public class ResolverUtils {
*/
public static List<String> getCompatibilityFeatures(MentionContext mention,
DiscourseEntity entity, TestSimilarityModel simModel) {
- List<String> compatFeatures = new ArrayList<String>();
+ List<String> compatFeatures = new ArrayList<>();
String semCompatible = getSemanticCompatibilityFeature(mention, entity, simModel);
compatFeatures.add(semCompatible);
String genCompatible = getGenderCompatibilityFeature(mention, entity);
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SingularPronounResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SingularPronounResolver.java
index 139f0d7..486c5ef 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SingularPronounResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SingularPronounResolver.java
@@ -55,8 +55,7 @@ public class SingularPronounResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention, entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
if (entity != null) { //generate pronoun w/ referent features
MentionContext cec = entity.getLastExtent();
//String gen = getPronounGender(pronoun);
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SpeechPronounResolver.java b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SpeechPronounResolver.java
index 7d080c6..d590212 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SpeechPronounResolver.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/resolver/SpeechPronounResolver.java
@@ -46,8 +46,7 @@ public class SpeechPronounResolver extends MaxentResolver {
@Override
protected List<String> getFeatures(MentionContext mention, DiscourseEntity entity) {
- List<String> features = new ArrayList<String>();
- features.addAll(super.getFeatures(mention, entity));
+ List<String> features = new ArrayList<String>(super.getFeatures(mention, entity));
if (entity != null) {
features.addAll(ResolverUtils.getPronounMatchFeatures(mention,entity));
List<String> contexts = ResolverUtils.getContextFeatures(mention);
@@ -107,7 +106,7 @@ public class SpeechPronounResolver extends MaxentResolver {
}
}
else if (mention.getHeadTokenTag().startsWith("PRP")) { // mention is a speech pronoun
- // cec can be either a speech pronoun or a propernoun
+ // cec can be either a speech pronoun or a proper noun
if (cec.getHeadTokenTag().startsWith("NNP")) {
//exclude antecedents not in the same sentence when they are not pronoun
return (mention.getSentenceNumber() - cec.getSentenceNumber() != 0);
@@ -116,12 +115,12 @@ public class SpeechPronounResolver extends MaxentResolver {
return false;
}
else {
- System.err.println("Unexpected candidate exluded: " + cec.toText());
+ System.err.println("Unexpected candidate excluded: " + cec.toText());
return true;
}
}
else {
- System.err.println("Unexpected mention exluded: " + mention.toText());
+ System.err.println("Unexpected mention excluded: " + mention.toText());
return true;
}
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/GenderEnum.java b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/GenderEnum.java
index d9fb598..bb1811f 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/GenderEnum.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/GenderEnum.java
@@ -21,13 +21,13 @@ package opennlp.tools.coref.sim;
* Enumeration of gender types.
*/
public class GenderEnum {
- private String gender;
+ private final String gender;
/** Male gender. */
public static final GenderEnum MALE = new GenderEnum("male");
/** Female gender. */
public static final GenderEnum FEMALE = new GenderEnum("female");
- /** Nueter gender. */
+ /** Neuter gender. */
public static final GenderEnum NEUTER = new GenderEnum("neuter");
/** Unknown gender. */
public static final GenderEnum UNKNOWN = new GenderEnum("unknown");
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/MaxentCompatibilityModel.java b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/MaxentCompatibilityModel.java
index 217beb9..8025fbf 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/MaxentCompatibilityModel.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/MaxentCompatibilityModel.java
@@ -20,7 +20,7 @@ package opennlp.tools.coref.sim;
import java.io.IOException;
/**
- * Model of mention compatibiltiy using a maxent model.
+ * Model of mention compatibility using a maxent model.
*/
public class MaxentCompatibilityModel {
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SemanticCompatibility.java b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SemanticCompatibility.java
index fa84387..2c544c0 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SemanticCompatibility.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SemanticCompatibility.java
@@ -18,12 +18,12 @@
package opennlp.tools.coref.sim;
/**
- * Class which models the semantic compatibility of an enity and the confidence of that association.
+ * Class which models the semantic compatibility of an entity and the confidence of that association.
*/
public class SemanticCompatibility {
- private SemanticEnum type;
- private double confidence;
+ private final SemanticEnum type;
+ private final double confidence;
public SemanticCompatibility(SemanticEnum type,double confidence) {
this.type = type;
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SimilarityModel.java b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SimilarityModel.java
index 8bf468c..bf77af0 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SimilarityModel.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/SimilarityModel.java
@@ -192,11 +192,11 @@ public class SimilarityModel implements TestSimilarityModel, TrainSimilarityMode
}
/**
- * Constructs a mapping between the specified entities and their head set.
+ * Constructs a mapping between the specified entities and their headset.
*
* @param entities Mapping between a key and a list of mentions which compose an entity.
*
- * @return a mapping between the keys of the specified entity mapping and the head set
+ * @return a mapping between the keys of the specified entity mapping and the headset
* generated from the mentions associated with that key.
*/
@SuppressWarnings("unchecked")
@@ -232,7 +232,7 @@ public class SimilarityModel implements TestSimilarityModel, TrainSimilarityMode
* @param entities A mapping between a key and a list of mentions.
*
* @return a mapping between each key in the specified entity map and the name types associated
- * with the each mention of that entity.
+ * with each mention of that entity.
*/
@SuppressWarnings("unchecked")
private Map<Integer, Set<String>> constructNameSets(Map<Integer, Context> entities) {
diff --git a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/TrainSimilarityModel.java b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/TrainSimilarityModel.java
index 1704013..f281431 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/coref/sim/TrainSimilarityModel.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/coref/sim/TrainSimilarityModel.java
@@ -23,13 +23,16 @@ import java.io.IOException;
* Interface for training a similarity, gender, or number model.
*/
public interface TrainSimilarityModel {
- public void trainModel() throws IOException;
+
+ void trainModel() throws IOException;
/**
- * Creates simialrity training pairs based on the specified extents.
+ * Creates similarity training pairs based on the specified extents.
* Extents are considered compatible is they are in the same coreference chain,
- * have the same named-entity tag, or share a common head word. Incompatible extents are chosen at random
- * from the set of extents which don't meet this criteria.
+ * have the same named-entity tag, or share a common head word.
+ * <p>
+ * Incompatible extents are chosen at random from the set of extents which don't meet these criteria.
+ *
* @param extents
*/
- public void setExtents(Context[] extents);
+ void setExtents(Context[] extents);
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/formats/muc/Muc6FullParseCorefSampleStreamFactory.java b/opennlp-coref/src/main/java/opennlp/tools/formats/muc/Muc6FullParseCorefSampleStreamFactory.java
index 137c0f3..06cda53 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/formats/muc/Muc6FullParseCorefSampleStreamFactory.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/formats/muc/Muc6FullParseCorefSampleStreamFactory.java
@@ -98,7 +98,7 @@ public class Muc6FullParseCorefSampleStreamFactory extends AbstractSampleStreamF
// How to load all these nameFinder models ?!
- // Lets make a param per model, not that nice, but ok!
+ // Let's make a param per model, not that nice, but ok!
Map<String, File> modelFileTagMap = new HashMap<String, File>();
diff --git a/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankLinker.java b/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankLinker.java
index c27d579..76d6516 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankLinker.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankLinker.java
@@ -35,12 +35,13 @@ import opennlp.tools.coref.mention.Mention;
import opennlp.tools.coref.mention.PTBMentionFinder;
import opennlp.tools.parser.Parse;
-
/**
- * This class perform coreference for treebank style parses.
+ * Performs coreference for treebank style parses.
* It will only perform coreference over constituents defined in the trees and
* will not generate new constituents for pre-nominal entities or sub-entities in
- * simple coordinated noun phrases. This linker requires that named-entity information also be provided.
+ * simple coordinated noun phrases.
+ * <p>
+ * This linker requires that named-entity information also be provided.
* This information can be added to the parse using the -parse option with EnglishNameFinder.
*
* @deprecated will be removed soon!
@@ -73,7 +74,7 @@ public class TreebankLinker extends DefaultLinker {
}
/**
- * Identitifies corefernce relationships for parsed input passed via standard in.
+ * Identifies co-reference relationships for parsed input passed via standard in.
* @param args The model directory.
* @throws IOException when the model directory can not be read.
*/
@@ -93,8 +94,8 @@ public class TreebankLinker extends DefaultLinker {
}
Linker treebankLinker = new TreebankLinker(dataDir,LinkerMode.TEST);
int sentenceNumber = 0;
- List<Mention> document = new ArrayList<Mention>();
- List<Parse> parses = new ArrayList<Parse>();
+ List<Mention> document = new ArrayList<>();
+ List<Parse> parses = new ArrayList<>();
for (String line = in.readLine();null != line;line = in.readLine()) {
if (line.equals("")) {
DiscourseEntity[] entities =
@@ -110,14 +111,14 @@ public class TreebankLinker extends DefaultLinker {
parses.add(p);
Mention[] extents = treebankLinker.getMentionFinder().getMentions(new DefaultParse(p,sentenceNumber));
//construct new parses for mentions which don't have constituents.
- for (int ei = 0, en = extents.length; ei < en; ei++) {
+ for (Mention extent : extents) {
//System.err.println("PennTreebankLiner.main: "+ei+" "+extents[ei]);
- if (extents[ei].getParse() == null) {
+ if (extent.getParse() == null) {
//not sure how to get head index, but its not used at this point.
- Parse snp = new Parse(p.getText(),extents[ei].getSpan(),"NML",1.0,0);
+ Parse snp = new Parse(p.getText(), extent.getSpan(), "NML", 1.0, 0);
p.insert(snp);
- extents[ei].setParse(new DefaultParse(snp,sentenceNumber));
+ extent.setParse(new DefaultParse(snp, sentenceNumber));
}
}
diff --git a/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankNameFinder.java b/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankNameFinder.java
index 9c89fef..c5ff3d3 100644
--- a/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankNameFinder.java
+++ b/opennlp-coref/src/main/java/opennlp/tools/lang/english/TreebankNameFinder.java
@@ -109,7 +109,7 @@ public class TreebankNameFinder {
String[] tokens = Span.spansToStrings(spans,line);
for (int fi = 0, fl = finders.length; fi < fl; fi++) {
nameSpans[fi] = finders[fi].nameFinder.find(tokens);
- //System.err.println("EnglighNameFinder.processText: "+tags[fi] + " "
+ //System.err.println("EnglishNameFinder.processText: "+tags[fi] + " "
// + java.util.Arrays.asList(finderTags[fi]));
nameOutcomes[fi] = NameFinderEventStream.generateOutcomes(nameSpans[fi], null, tokens.length);
}
diff --git a/opennlp-dl/src/main/java/opennlp/tools/dl/DataReader.java b/opennlp-dl/src/main/java/opennlp/tools/dl/DataReader.java
index c75e2eb..26934bc 100644
--- a/opennlp-dl/src/main/java/opennlp/tools/dl/DataReader.java
+++ b/opennlp-dl/src/main/java/opennlp/tools/dl/DataReader.java
@@ -111,7 +111,7 @@ public class DataReader implements DataSetIterator {
/**
* Creates a reader with the specified arguments
* @param dataDirPath data directory
- * @param labelNames list of labels (names should match sub directory names)
+ * @param labelNames list of labels (names should match subdirectory names)
* @param embedder embeddings to convert words to vectors
* @param batchSize mini batch size for DL4j training
* @param maxSeqLength truncate sequences that are longer than this.
diff --git a/opennlp-dl/src/main/java/opennlp/tools/dl/RNN.java b/opennlp-dl/src/main/java/opennlp/tools/dl/RNN.java
index 5a4d931..3c143c1 100644
--- a/opennlp-dl/src/main/java/opennlp/tools/dl/RNN.java
+++ b/opennlp-dl/src/main/java/opennlp/tools/dl/RNN.java
@@ -147,7 +147,7 @@ public class RNN {
INDArray inputs = getSequence(p);
INDArray targets = getSequence(p + 1);
- // sample from the model every now and then
+ // sample from the model now and then
if (n % 1000 == 0 && n > 0) {
String txt = sample(inputs.getInt(0));
System.out.printf("\n---\n %s \n----\n", txt);
diff --git a/opennlp-dl/src/main/java/opennlp/tools/dl/StackedRNN.java b/opennlp-dl/src/main/java/opennlp/tools/dl/StackedRNN.java
index 2a061ce..f60414c 100644
--- a/opennlp-dl/src/main/java/opennlp/tools/dl/StackedRNN.java
+++ b/opennlp-dl/src/main/java/opennlp/tools/dl/StackedRNN.java
@@ -117,7 +117,7 @@ public class StackedRNN extends RNN {
INDArray inputs = getSequence(p);
INDArray targets = getSequence(p + 1);
- // sample from the model every now and then
+ // sample from the model now and then
if (n % 1000 == 0 && n > 0) {
for (int i = 0; i < 3; i++) {
String txt = sample(inputs.getInt(0));
diff --git a/opennlp-similarity/README.md b/opennlp-similarity/README.md
index 2caf30f..7153beb 100644
--- a/opennlp-similarity/README.md
+++ b/opennlp-similarity/README.md
@@ -1,7 +1,7 @@
# OpenNLP.Similarity Component
It is a project under Apache OpenNLP which subjects results of parsing, part-of-speech tagging and rhetoric parsing to machine learning.
-It is leveraged in search, content generation & enrichment, chat bots and other text processing domains where relevance assessment task is a key.
+It is leveraged in search, content generation & enrichment, chatbots and other text processing domains where relevance assessment task is a key.
## What is OpenNLP.Similarity?
@@ -19,7 +19,7 @@ OpenNLP.Similarity is an NLP engine which solves a number of text processing and
OpenNLP similarity provides a series of techniques to support the overall content pipeline, from text collection to cleaning, classification, personalization and distribution. Technology and implementation of content pipeline developed at eBay is described [here](https://github.com/bgalitsky/relevance-based-on-parse-trees/tree/master/examples/ContentPipeline.pdf).
## Installation
- 0) Do [`git clone`](https://github.com/bgalitsky/relevance-based-on-parse-trees.git) to setup the environment including resources. Besides what you get from git, `/resources` directory requires some additional work:
+ 0) Do [`git clone`](https://github.com/bgalitsky/relevance-based-on-parse-trees.git) to set up the environment including resources. Besides what you get from git, `/resources` directory requires some additional work:
1) Download the main [jar](https://github.com/bgalitsky/relevance-based-on-parse-trees/blob/master/opennlp-similarity.11.jar).
@@ -36,7 +36,7 @@ OpenNLP similarity provides a series of techniques to support the overall conten
- new_vn.zip needs to be unzipped
- OpenNLP models need to be downloaded into the directory 'models' from [here](http://opennlp.sourceforge.net/models-1.5/)
- As a result the following folders should be in in /resources:
+ As a result the following folders should be in /resources:
As obtained [from git](https://github.com/bgalitsky/relevance-based-on-parse-trees/tree/master/src/test/resources):
<li>/new_vn (VerbNet)</li>
<li>/maps (some lookup files such as products, brands, first names etc.)</li>
@@ -66,7 +66,7 @@ It takes two texts and returns the cardinality of a maximum common subgraph repr
function which returns the list of [common phrases between these paragraph]s.
-To avoid re-parsing the same strings and improve the speed, use
+To avoid reparsing the same strings and improve the speed, use
`List<List<ParseTreeChunk>> assessRelevanceCache(String para1, String para2)`
@@ -147,11 +147,11 @@ Here's the link to the book on [question-answering](https://www.amazon.com/Natur
and [research papers](https://scholar.google.com/citations?hl=ru&user=kR_M3HIAAAAJ).
-Also the recent [book related to reasoning and linguistics in humans & machines](https://www.amazon.com/Computational-Autism-Human-Computer-Interaction-Galitsky/dp/3319399713)
+also the recent [book related to reasoning and linguistics in humans & machines](https://www.amazon.com/Computational-Autism-Human-Computer-Interaction-Galitsky/dp/3319399713)
## Configuring OpenNLP.Similarity component
-VerbNet model is included by default, so that the hand-coded meanings of the verb are used when simularity between verb phrases are computed.
+VerbNet model is included by default, so that the hand-coded meanings of the verb are used when similarity between verb phrases are computed.
To include word2vector model, [download it](https://deeplearning4j.org/) and make sure the following path is valid:
`resourceDir + "/w2v/GoogleNews-vectors-negative300.bin.gz"`
\ No newline at end of file
diff --git a/opennlp-similarity/README.txt b/opennlp-similarity/README.txt
index a0ae062..832c571 100644
--- a/opennlp-similarity/README.txt
+++ b/opennlp-similarity/README.txt
@@ -23,7 +23,7 @@ Similarity component can be used on top of search to improve relevance, computin
Also, this component is useful for web mining of images, videos, forums, blogs, and other media with textual descriptions. Such applications as content generation
and filtering meaningless speech recognition results are included in the sample applications of this component.
Relevance assessment is based on machine learning of syntactic parse trees (constituency trees, http://en.wikipedia.org/wiki/Parse_tree).
-The similarity score is calculated as the size of all maximal common sub-trees for sentences from a pair of texts (
+The similarity score is calculated as the size of all maximal common subtrees for sentences from a pair of texts (
www.aaai.org/ocs/index.php/WS/AAAIW11/paper/download/3971/4187, www.aaai.org/ocs/index.php/FLAIRS/FLAIRS11/paper/download/2573/3018,
www.aaai.org/ocs/index.php/SSS/SSS10/paper/download/1146/1448).
The objective of Similarity component is to give an application engineer as tool for text relevance which can be used as a black box, no need to understand
diff --git a/opennlp-similarity/RELEASE_NOTES.html b/opennlp-similarity/RELEASE_NOTES.html
index 447b27f..8dea1bf 100644
--- a/opennlp-similarity/RELEASE_NOTES.html
+++ b/opennlp-similarity/RELEASE_NOTES.html
@@ -42,7 +42,7 @@ Similarity component can be used on top of search to improve relevance, computin
Also, this component is useful for web mining of images, videos, forums, blogs, and other media with textual descriptions. Such applications as content generation
and filtering meaningless speech recognition results are included in the sample applications of this component.
Relevance assessment is based on machine learning of syntactic parse trees (constituency trees, http://en.wikipedia.org/wiki/Parse_tree).
-The similarity score is calculated as the size of all maximal common sub-trees for sentences from a pair of texts (
+The similarity score is calculated as the size of all maximal common subtrees for sentences from a pair of texts (
www.aaai.org/ocs/index.php/WS/AAAIW11/paper/download/3971/4187, www.aaai.org/ocs/index.php/FLAIRS/FLAIRS11/paper/download/2573/3018,
www.aaai.org/ocs/index.php/SSS/SSS10/paper/download/1146/1448).
The objective of Similarity component is to give an application engineer as tool for text relevance which can be used as a black box, no need to understand
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/BingWebQueryRunnerThread.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/BingWebQueryRunnerThread.java
index b328759..0fd1752 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/BingWebQueryRunnerThread.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/BingWebQueryRunnerThread.java
@@ -28,13 +28,12 @@ public class BingWebQueryRunnerThread extends BingQueryRunner implements Runnabl
// Create the listener list
protected javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList();
- // This methods allows classes to register for MyEvents
-
+ // This method allows classes to register for MyEvents
public void addMyEventListener(MyEventListener listener) {
listenerList.add(MyEventListener.class, listener);
}
- // This methods allows classes to unregister for MyEvents
+ // This method allows classes to unregister for MyEvents
public void removeMyEventListener(MyEventListener listener) {
listenerList.remove(MyEventListener.class, listener);
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/cgRequestForm.html b/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/cgRequestForm.html
index b352b20..0b8013b 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/cgRequestForm.html
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/contentgen/multithreaded/cgRequestForm.html
@@ -25,7 +25,7 @@
</select>
</p>
<p>
- Number of Bing calls to write a this essay: <input type='text' name='stepsNum' value='20' size='5' maxlength='10'/>
+ Number of Bing calls to write this essay: <input type='text' name='stepsNum' value='20' size='5' maxlength='10'/>
Number of Bing search results for each call to use for writing: <input type='text' name='searchResultsNum' value='100' size='5' maxlength='10'/>
</p>
<p>
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/object_dedup/SimilarityAccessorBase.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/object_dedup/SimilarityAccessorBase.java
index 1af52d9..386dbeb 100755
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/object_dedup/SimilarityAccessorBase.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/object_dedup/SimilarityAccessorBase.java
@@ -604,7 +604,7 @@ public class SimilarityAccessorBase
}
// accept common expression
LOG.info("Formed common entity = " + entityExpression);
- reason.append("Formed common entity = " + entityExpression + "\n");
+ reason.append("Formed common entity = ").append(entityExpression).append("\n");
// now go to the web / bing api with this common expression
List<HitBase> searchResult = webSearch.runSearch(entityExpression);
float entityScore = 0f;
@@ -615,7 +615,7 @@ public class SimilarityAccessorBase
{
String lookup = item.getTitle();
LOG.info("Bing hit title = '" + lookup + "'");
- reason.append("Bing hit title = '" + lookup + "'\n");
+ reason.append("Bing hit title = '").append(lookup).append("'\n");
if (count > 4)
break;
count++;
@@ -707,8 +707,7 @@ public class SimilarityAccessorBase
if (d > thresh) // 0.8)
{
- reason.append("Found common search result title for group names '" + lookup1 + " < > "
- + lookup2 + " sim = " + d + "\n");
+ reason.append("Found common search result title for group names '").append(lookup1).append(" < > ").append(lookup2).append(" sim = ").append(d).append("\n");
LOG.info(("Found common search result title for group names '" + lookup1 + " < > " + lookup2
+ " sim = " + d));
score++;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/POStags.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/POStags.java
index fafdef0..68bebbd 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/POStags.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/POStags.java
@@ -19,73 +19,73 @@ package opennlp.tools.apps.relevanceVocabs;
public interface POStags {
// added new POS types for infinitive phrase and participle phrase
- public static final String TYPE_STP = "STP"; // infinitive phrase
- public static final String TYPE_SGP = "SGP"; // present participle phrase
- public static final String TYPE_SNP = "SNP"; // past participle phrase
+ String TYPE_STP = "STP"; // infinitive phrase
+ String TYPE_SGP = "SGP"; // present participle phrase
+ String TYPE_SNP = "SNP"; // past participle phrase
// below are the standard POS types,
// http://bulba.sdsu.edu/jeanette/thesis/PennTags.html
- public static final String TYPE_ADJP = "ADJP";
- public static final String TYPE_ADVP = "ADVP";
- public static final String TYPE_CC = "CC";
- public static final String TYPE_CD = "CD";
- public static final String TYPE_CONJP = "CONJP";
- public static final String TYPE_DT = "DT";
- public static final String TYPE_EX = "EX";
- public static final String TYPE_FRAG = "FRAG";
- public static final String TYPE_FW = "FW";
- public static final String TYPE_IN = "IN";
- public static final String TYPE_INTJ = "INTJ";
- public static final String TYPE_JJ = "JJ";
- public static final String TYPE_JJR = "JJR";
- public static final String TYPE_JJS = "JJS";
- public static final String TYPE_LS = "LS";
- public static final String TYPE_LST = "LST";
- public static final String TYPE_MD = "MD";
- public static final String TYPE_NAC = "NAC";
- public static final String TYPE_NN = "NN";
- public static final String TYPE_NNS = "NNS";
- public static final String TYPE_NNP = "NNP";
- public static final String TYPE_NNPS = "NNPS";
- public static final String TYPE_NP = "NP";
- public static final String TYPE_NX = "NX";
- public static final String TYPE_PDT = "PDT";
- public static final String TYPE_POS = "POS";
- public static final String TYPE_PP = "PP";
- public static final String TYPE_PRN = "PRN";
- public static final String TYPE_PRP = "PRP";
- public static final String TYPE_PRP$ = "PRP$";
- public static final String TYPE_PRT = "PRT";
- public static final String TYPE_QP = "QP";
- public static final String TYPE_RB = "RB";
- public static final String TYPE_RBR = "RBR";
- public static final String TYPE_RBS = "RBS";
- public static final String TYPE_RP = "RP";
- public static final String TYPE_RRC = "RRC";
- public static final String TYPE_S = "S";
- public static final String TYPE_SBAR = "SBAR";
- public static final String TYPE_SBARQ = "SBARQ";
- public static final String TYPE_SINV = "SINV";
- public static final String TYPE_SQ = "SQ";
- public static final String TYPE_SYM = "SYM";
- public static final String TYPE_TO = "TO";
- public static final String TYPE_TOP = "TOP";
- public static final String TYPE_UCP = "UCP";
- public static final String TYPE_UH = "UH";
- public static final String TYPE_VB = "VB";
- public static final String TYPE_VBD = "VBD";
- public static final String TYPE_VBG = "VBG";
- public static final String TYPE_VBN = "VBN";
- public static final String TYPE_VBP = "VBP";
- public static final String TYPE_VBZ = "VBZ";
- public static final String TYPE_VP = "VP";
- public static final String TYPE_WDT = "WDT";
- public static final String TYPE_WHADJP = "WHADJP";
- public static final String TYPE_WHADVP = "WHADVP";
- public static final String TYPE_WHNP = "WHNP";
- public static final String TYPE_WHPP = "WHPP";
- public static final String TYPE_WP = "WP";
- public static final String TYPE_WP$ = "WP$";
- public static final String TYPE_WRB = "WRB";
- public static final String TYPE_X = "X";
+ String TYPE_ADJP = "ADJP";
+ String TYPE_ADVP = "ADVP";
+ String TYPE_CC = "CC";
+ String TYPE_CD = "CD";
+ String TYPE_CONJP = "CONJP";
+ String TYPE_DT = "DT";
+ String TYPE_EX = "EX";
+ String TYPE_FRAG = "FRAG";
+ String TYPE_FW = "FW";
+ String TYPE_IN = "IN";
+ String TYPE_INTJ = "INTJ";
+ String TYPE_JJ = "JJ";
+ String TYPE_JJR = "JJR";
+ String TYPE_JJS = "JJS";
+ String TYPE_LS = "LS";
+ String TYPE_LST = "LST";
+ String TYPE_MD = "MD";
+ String TYPE_NAC = "NAC";
+ String TYPE_NN = "NN";
+ String TYPE_NNS = "NNS";
+ String TYPE_NNP = "NNP";
+ String TYPE_NNPS = "NNPS";
+ String TYPE_NP = "NP";
+ String TYPE_NX = "NX";
+ String TYPE_PDT = "PDT";
+ String TYPE_POS = "POS";
+ String TYPE_PP = "PP";
+ String TYPE_PRN = "PRN";
+ String TYPE_PRP = "PRP";
+ String TYPE_PRP$ = "PRP$";
+ String TYPE_PRT = "PRT";
+ String TYPE_QP = "QP";
+ String TYPE_RB = "RB";
+ String TYPE_RBR = "RBR";
+ String TYPE_RBS = "RBS";
+ String TYPE_RP = "RP";
+ String TYPE_RRC = "RRC";
+ String TYPE_S = "S";
+ String TYPE_SBAR = "SBAR";
+ String TYPE_SBARQ = "SBARQ";
+ String TYPE_SINV = "SINV";
+ String TYPE_SQ = "SQ";
+ String TYPE_SYM = "SYM";
+ String TYPE_TO = "TO";
+ String TYPE_TOP = "TOP";
+ String TYPE_UCP = "UCP";
+ String TYPE_UH = "UH";
+ String TYPE_VB = "VB";
+ String TYPE_VBD = "VBD";
+ String TYPE_VBG = "VBG";
+ String TYPE_VBN = "VBN";
+ String TYPE_VBP = "VBP";
+ String TYPE_VBZ = "VBZ";
+ String TYPE_VP = "VP";
+ String TYPE_WDT = "WDT";
+ String TYPE_WHADJP = "WHADJP";
+ String TYPE_WHADVP = "WHADVP";
+ String TYPE_WHNP = "WHNP";
+ String TYPE_WHPP = "WHPP";
+ String TYPE_WP = "WP";
+ String TYPE_WP$ = "WP$";
+ String TYPE_WRB = "WRB";
+ String TYPE_X = "X";
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/PhraseProcessor.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/PhraseProcessor.java
index 33b4b00..7ffcf82 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/PhraseProcessor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/PhraseProcessor.java
@@ -168,8 +168,7 @@ public class PhraseProcessor {
for (String w : qs) {
if (w.toLowerCase().equals(w)) // idf only two words then
// has to be person name,
- // title or geo
- // location
+ // title or geolocation
bAccept = false;
}
if (!bAccept)
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SentimentVocab.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SentimentVocab.java
index 98ac4b2..4c3474e 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SentimentVocab.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SentimentVocab.java
@@ -17,6 +17,7 @@
package opennlp.tools.apps.relevanceVocabs;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -129,7 +130,7 @@ public class SentimentVocab {
if (word == null)
return null;
- // get the normalized form of the word
+ // get the normalized form
//word = WordDictionary.getInstance().getLemmaOrWord(word);
return sentimentMap.get(word);
@@ -139,7 +140,7 @@ public class SentimentVocab {
if (word == null)
return null;
- // get the normalized form of the word
+ // get the normalized form
//word = WordDictionary.getInstance().getLemmaOrWord(word, posType);
return sentimentMap.get(word);
@@ -209,8 +210,6 @@ public class SentimentVocab {
wordSet = new HashSet<String>();
wordSetMap.put(posType, wordSet);
}
- for (String word : words) {
- wordSet.add(word);
- }
+ wordSet.addAll(Arrays.asList(words));
}
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SynonymMap.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SynonymMap.java
index 283435a..9d236f3 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SynonymMap.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/relevanceVocabs/SynonymMap.java
@@ -18,336 +18,335 @@
package opennlp.tools.apps.relevanceVocabs;
import java.io.IOException;
- import java.io.InputStream;
- import java.nio.ByteBuffer;
- import java.nio.charset.Charset;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.TreeMap;
- import java.util.TreeSet;
-
-
- public class SynonymMap {
-
- /** the index data; Map<String word, String[] synonyms> */
- private final HashMap<String,String[]> table;
-
- private static final String[] EMPTY = new String[0];
-
- private static final boolean DEBUG = false;
-
- /**
- * Constructs an instance, loading WordNet synonym data from the given input
- * stream. Finally closes the stream. The words in the stream must be in
- * UTF-8 or a compatible subset (for example ASCII, MacRoman, etc.).
- *
- * @param input
- * the stream to read from (null indicates an empty synonym map)
- * @throws IOException
- * if an error occurred while reading the stream.
- */
- public SynonymMap(InputStream input) throws IOException {
- this.table = input == null ? new HashMap<String,String[]>(0) : read(toByteArray(input));
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+public class SynonymMap {
+
+ /** the index data; Map<String word, String[] synonyms> */
+ private final HashMap<String,String[]> table;
+
+ private static final String[] EMPTY = new String[0];
+
+ private static final boolean DEBUG = false;
+
+ /**
+ * Constructs an instance, loading WordNet synonym data from the given input
+ * stream. Finally, closes the stream. The words in the stream must be in
+ * UTF-8 or a compatible subset (for example ASCII, MacRoman, etc.).
+ *
+ * @param input
+ * the stream to read from (null indicates an empty synonym map)
+ * @throws IOException
+ * if an error occurred while reading the stream.
+ */
+ public SynonymMap(InputStream input) throws IOException {
+ this.table = input == null ? new HashMap<>(0) : read(toByteArray(input));
+ }
+
+ /**
+ * Returns the synonym set for the given word, sorted ascending.
+ *
+ * @param word
+ * the word to lookup (must be in lowercase).
+ * @return the synonyms; a set of zero or more words, sorted ascending, each
+ * word containing lowercase characters that satisfy
+ * <code>Character.isLetter()</code>.
+ */
+ public String[] getSynonyms(String word) {
+ String[] synonyms = table.get(word);
+ if (synonyms == null) return EMPTY;
+ String[] copy = new String[synonyms.length]; // copy for guaranteed immutability
+ System.arraycopy(synonyms, 0, copy, 0, synonyms.length);
+ return copy;
+ }
+
+ /**
+ * Returns a String representation of the index data for debugging purposes.
+ *
+ * @return a String representation
+ */
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder();
+ Iterator<String> iter = new TreeMap<>(table).keySet().iterator();
+ int count = 0;
+ int f0 = 0;
+ int f1 = 0;
+ int f2 = 0;
+ int f3 = 0;
+
+ while (iter.hasNext()) {
+ String word = iter.next();
+ buf.append(word).append(":");
+ String[] synonyms = getSynonyms(word);
+ buf.append(Arrays.asList(synonyms));
+ buf.append("\n");
+ count += synonyms.length;
+ if (synonyms.length == 0) f0++;
+ if (synonyms.length == 1) f1++;
+ if (synonyms.length == 2) f2++;
+ if (synonyms.length == 3) f3++;
+ }
+
+ buf.append("\n\nkeys=").append(table.size()).append(", synonyms=").append(count).append(", f0=").append(f0).append(", f1=").append(f1).append(", f2=").append(f2).append(", f3=").append(f3);
+ return buf.toString();
+ }
+
+ /**
+ * Analyzes/transforms the given word on input stream loading. This default implementation simply
+ * lower-cases the word. Override this method with a custom stemming
+ * algorithm or similar, if desired.
+ *
+ * @param word
+ * the word to analyze
+ * @return the same word, or a different word (or null to indicate that the
+ * word should be ignored)
+ */
+ protected String analyze(String word) {
+ return word.toLowerCase();
+ }
+
+ private static boolean isValid(String str) {
+ for (int i=str.length(); --i >= 0; ) {
+ if (!Character.isLetter(str.charAt(i))) return false;
+ }
+ return true;
+ }
+
+ private HashMap<String,String[]> read(byte[] data) {
+ int WORDS = (int) (76401 / 0.7); // presizing
+ int GROUPS = (int) (88022 / 0.7); // presizing
+ HashMap<String,ArrayList<Integer>> word2Groups = new HashMap<>(WORDS); // Map<String word, int[] groups>
+ HashMap<Integer,ArrayList<String>> group2Words = new HashMap<>(GROUPS); // Map<int group, String[] words>
+ HashMap<String,String> internedWords = new HashMap<>(WORDS);// Map<String word, String word>
+
+ Charset charset = StandardCharsets.UTF_8;
+ int lastNum = -1;
+ Integer lastGroup = null;
+ int len = data.length;
+ int i=0;
+
+ while (i < len) { // until EOF
+ /* Part A: Parse a line */
+
+ // scan to beginning of group
+ while (i < len && data[i] != '(') i++;
+ if (i >= len) break; // EOF
+ i++;
+
+ // parse group
+ int num = 0;
+ while (i < len && data[i] != ',') {
+ num = 10*num + (data[i] - 48);
+ i++;
}
-
- /**
- * Returns the synonym set for the given word, sorted ascending.
- *
- * @param word
- * the word to lookup (must be in lowercase).
- * @return the synonyms; a set of zero or more words, sorted ascending, each
- * word containing lowercase characters that satisfy
- * <code>Character.isLetter()</code>.
+ i++;
+ // if (DEBUG) System.err.println("num="+ num);
+
+ // scan to beginning of word
+ while (i < len && data[i] != '\'') i++;
+ i++;
+
+ // scan to end of word
+ int start = i;
+ do {
+ while (i < len && data[i] != '\'') i++;
+ i++;
+ } while (i < len && data[i] != ','); // word must end with "',"
+
+ if (i >= len) break; // EOF
+ String word = charset.decode(ByteBuffer.wrap(data, start, i-start-1)).toString();
+ // String word = new String(data, 0, start, i-start-1); // ASCII
+
+ /*
+ * Part B: ignore phrases (with spaces and hyphens) and
+ * non-alphabetic words, and let user customize word (e.g. do some
+ * stemming)
*/
- public String[] getSynonyms(String word) {
- String[] synonyms = table.get(word);
- if (synonyms == null) return EMPTY;
- String[] copy = new String[synonyms.length]; // copy for guaranteed immutability
- System.arraycopy(synonyms, 0, copy, 0, synonyms.length);
- return copy;
+ if (!isValid(word)) continue; // ignore
+ word = analyze(word);
+ if (word == null || word.length() == 0) continue; // ignore
+
+
+ /* Part C: Add (group,word) to tables */
+
+ // ensure compact string representation, minimizing memory overhead
+ String w = internedWords.get(word);
+ if (w == null) {
+ word = new String(word); // ensure compact string
+ internedWords.put(word, word);
+ } else {
+ word = w;
}
-
- /**
- * Returns a String representation of the index data for debugging purposes.
- *
- * @return a String representation
- */
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- Iterator<String> iter = new TreeMap<String,String[]>(table).keySet().iterator();
- int count = 0;
- int f0 = 0;
- int f1 = 0;
- int f2 = 0;
- int f3 = 0;
-
- while (iter.hasNext()) {
- String word = iter.next();
- buf.append(word + ":");
- String[] synonyms = getSynonyms(word);
- buf.append(Arrays.asList(synonyms));
- buf.append("\n");
- count += synonyms.length;
- if (synonyms.length == 0) f0++;
- if (synonyms.length == 1) f1++;
- if (synonyms.length == 2) f2++;
- if (synonyms.length == 3) f3++;
- }
-
- buf.append("\n\nkeys=" + table.size() + ", synonyms=" + count + ", f0=" + f0 +", f1=" + f1 + ", f2=" + f2 + ", f3=" + f3);
- return buf.toString();
+
+ Integer group = lastGroup;
+ if (num != lastNum) {
+ group = num;
+ lastGroup = group;
+ lastNum = num;
}
-
- /**
- * Analyzes/transforms the given word on input stream loading. This default implementation simply
- * lowercases the word. Override this method with a custom stemming
- * algorithm or similar, if desired.
- *
- * @param word
- * the word to analyze
- * @return the same word, or a different word (or null to indicate that the
- * word should be ignored)
- */
- protected String analyze(String word) {
- return word.toLowerCase();
+
+ // add word --> group
+ ArrayList<Integer> groups = word2Groups.get(word);
+ if (groups == null) {
+ groups = new ArrayList<>(1);
+ word2Groups.put(word, groups);
}
-
- private static boolean isValid(String str) {
- for (int i=str.length(); --i >= 0; ) {
- if (!Character.isLetter(str.charAt(i))) return false;
- }
- return true;
+ groups.add(group);
+
+ // add group --> word
+ ArrayList<String> words = group2Words.get(group);
+ if (words == null) {
+ words = new ArrayList<>(1);
+ group2Words.put(group, words);
}
-
- private HashMap<String,String[]> read(byte[] data) {
- int WORDS = (int) (76401 / 0.7); // presizing
- int GROUPS = (int) (88022 / 0.7); // presizing
- HashMap<String,ArrayList<Integer>> word2Groups = new HashMap<String,ArrayList<Integer>>(WORDS); // Map<String word, int[] groups>
- HashMap<Integer,ArrayList<String>> group2Words = new HashMap<Integer,ArrayList<String>>(GROUPS); // Map<int group, String[] words>
- HashMap<String,String> internedWords = new HashMap<String,String>(WORDS);// Map<String word, String word>
-
- Charset charset = Charset.forName("UTF-8");
- int lastNum = -1;
- Integer lastGroup = null;
- int len = data.length;
- int i=0;
-
- while (i < len) { // until EOF
- /* Part A: Parse a line */
-
- // scan to beginning of group
- while (i < len && data[i] != '(') i++;
- if (i >= len) break; // EOF
- i++;
-
- // parse group
- int num = 0;
- while (i < len && data[i] != ',') {
- num = 10*num + (data[i] - 48);
- i++;
- }
- i++;
- // if (DEBUG) System.err.println("num="+ num);
-
- // scan to beginning of word
- while (i < len && data[i] != '\'') i++;
- i++;
-
- // scan to end of word
- int start = i;
- do {
- while (i < len && data[i] != '\'') i++;
- i++;
- } while (i < len && data[i] != ','); // word must end with "',"
-
- if (i >= len) break; // EOF
- String word = charset.decode(ByteBuffer.wrap(data, start, i-start-1)).toString();
- // String word = new String(data, 0, start, i-start-1); // ASCII
-
- /*
- * Part B: ignore phrases (with spaces and hyphens) and
- * non-alphabetic words, and let user customize word (e.g. do some
- * stemming)
- */
- if (!isValid(word)) continue; // ignore
- word = analyze(word);
- if (word == null || word.length() == 0) continue; // ignore
-
-
- /* Part C: Add (group,word) to tables */
-
- // ensure compact string representation, minimizing memory overhead
- String w = internedWords.get(word);
- if (w == null) {
- word = new String(word); // ensure compact string
- internedWords.put(word, word);
- } else {
- word = w;
- }
-
- Integer group = lastGroup;
- if (num != lastNum) {
- group = Integer.valueOf(num);
- lastGroup = group;
- lastNum = num;
- }
-
- // add word --> group
- ArrayList<Integer> groups = word2Groups.get(word);
- if (groups == null) {
- groups = new ArrayList<Integer>(1);
- word2Groups.put(word, groups);
+ words.add(word);
+ }
+
+
+ /* Part D: compute index data structure */
+ HashMap<String,String[]> word2Syns = createIndex(word2Groups, group2Words);
+
+ /* Part E: minimize memory consumption by a factor 3 (or so) */
+ // if (true) return word2Syns;
+ word2Groups = null; // help gc
+ //TODO: word2Groups.clear(); would be more appropriate ?
+ group2Words = null; // help gc
+ //TODO: group2Words.clear(); would be more appropriate ?
+
+ return optimize(word2Syns, internedWords);
+ }
+
+ private HashMap<String,String[]> createIndex(Map<String,ArrayList<Integer>> word2Groups, Map<Integer,ArrayList<String>> group2Words) {
+ HashMap<String,String[]> word2Syns = new HashMap<>();
+
+ for (final Map.Entry<String,ArrayList<Integer>> entry : word2Groups.entrySet()) { // for each word
+ ArrayList<Integer> group = entry.getValue();
+ String word = entry.getKey();
+
+ // HashSet synonyms = new HashSet();
+ TreeSet<String> synonyms = new TreeSet<>();
+ for (int i=group.size(); --i >= 0; ) { // for each groupID of word
+ ArrayList<String> words = group2Words.get(group.get(i));
+ for (int j=words.size(); --j >= 0; ) { // add all words
+ String synonym = words.get(j); // note that w and word are interned
+ if (synonym != word) { // a word implicitly is its own synonym
+ synonyms.add(synonym);
}
- groups.add(group);
-
- // add group --> word
- ArrayList<String> words = group2Words.get(group);
- if (words == null) {
- words = new ArrayList<String>(1);
- group2Words.put(group, words);
- }
- words.add(word);
}
-
-
- /* Part D: compute index data structure */
- HashMap<String,String[]> word2Syns = createIndex(word2Groups, group2Words);
-
- /* Part E: minimize memory consumption by a factor 3 (or so) */
- // if (true) return word2Syns;
- word2Groups = null; // help gc
- //TODO: word2Groups.clear(); would be more appropriate ?
- group2Words = null; // help gc
- //TODO: group2Words.clear(); would be more appropriate ?
-
- return optimize(word2Syns, internedWords);
}
-
- private HashMap<String,String[]> createIndex(Map<String,ArrayList<Integer>> word2Groups, Map<Integer,ArrayList<String>> group2Words) {
- HashMap<String,String[]> word2Syns = new HashMap<String,String[]>();
-
- for (final Map.Entry<String,ArrayList<Integer>> entry : word2Groups.entrySet()) { // for each word
- ArrayList<Integer> group = entry.getValue();
- String word = entry.getKey();
-
- // HashSet synonyms = new HashSet();
- TreeSet<String> synonyms = new TreeSet<String>();
- for (int i=group.size(); --i >= 0; ) { // for each groupID of word
- ArrayList<String> words = group2Words.get(group.get(i));
- for (int j=words.size(); --j >= 0; ) { // add all words
- String synonym = words.get(j); // note that w and word are interned
- if (synonym != word) { // a word is implicitly it's own synonym
- synonyms.add(synonym);
- }
- }
- }
-
- int size = synonyms.size();
- if (size > 0) {
- String[] syns = new String[size];
- if (size == 1)
- syns[0] = synonyms.first();
- else
- synonyms.toArray(syns);
- // if (syns.length > 1) Arrays.sort(syns);
- // if (DEBUG) System.err.println("word=" + word + ":" + Arrays.asList(syns));
- word2Syns.put(word, syns);
- }
- }
-
- return word2Syns;
+
+ int size = synonyms.size();
+ if (size > 0) {
+ String[] syns = new String[size];
+ if (size == 1)
+ syns[0] = synonyms.first();
+ else
+ synonyms.toArray(syns);
+ // if (syns.length > 1) Arrays.sort(syns);
+ // if (DEBUG) System.err.println("word=" + word + ":" + Arrays.asList(syns));
+ word2Syns.put(word, syns);
}
-
- private HashMap<String,String[]> optimize(HashMap<String,String[]> word2Syns, HashMap<String,String> internedWords) {
- if (DEBUG) {
- System.err.println("before gc");
- for (int i=0; i < 10; i++) System.gc();
- System.err.println("after gc");
- }
-
- // collect entries
- int len = 0;
- int size = word2Syns.size();
- String[][] allSynonyms = new String[size][];
- String[] words = new String[size];
- Iterator<Map.Entry<String,String[]>> iter = word2Syns.entrySet().iterator();
- for (int j=0; j < size; j++) {
- Map.Entry<String,String[]> entry = iter.next();
- allSynonyms[j] = entry.getValue();
- words[j] = entry.getKey();
- len += words[j].length();
- }
-
- // assemble large string containing all words
- StringBuilder buf = new StringBuilder(len);
- for (int j=0; j < size; j++) buf.append(words[j]);
- String allWords = new String(buf.toString()); // ensure compact string across JDK versions
- buf = null;
-
- // intern words at app level via memory-overlaid substrings
- for (int p=0, j=0; j < size; j++) {
- String word = words[j];
- internedWords.put(word, allWords.substring(p, p + word.length()));
- p += word.length();
- }
-
- // replace words with interned words
- for (int j=0; j < size; j++) {
- String[] syns = allSynonyms[j];
- for (int k=syns.length; --k >= 0; ) {
- syns[k] = internedWords.get(syns[k]);
- }
- word2Syns.remove(words[j]);
- word2Syns.put(internedWords.get(words[j]), syns);
- }
-
- if (DEBUG) {
- words = null;
- allSynonyms = null;
- internedWords = null;
- allWords = null;
- System.err.println("before gc");
- for (int i=0; i < 10; i++) System.gc();
- System.err.println("after gc");
- }
- return word2Syns;
+ }
+
+ return word2Syns;
+ }
+
+ private HashMap<String,String[]> optimize(HashMap<String,String[]> word2Syns, HashMap<String,String> internedWords) {
+ if (DEBUG) {
+ System.err.println("before gc");
+ for (int i=0; i < 10; i++) System.gc();
+ System.err.println("after gc");
+ }
+
+ // collect entries
+ int len = 0;
+ int size = word2Syns.size();
+ String[][] allSynonyms = new String[size][];
+ String[] words = new String[size];
+ Iterator<Map.Entry<String,String[]>> iter = word2Syns.entrySet().iterator();
+ for (int j=0; j < size; j++) {
+ Map.Entry<String,String[]> entry = iter.next();
+ allSynonyms[j] = entry.getValue();
+ words[j] = entry.getKey();
+ len += words[j].length();
+ }
+
+ // assemble large string containing all words
+ StringBuilder buf = new StringBuilder(len);
+ for (int j=0; j < size; j++) buf.append(words[j]);
+ String allWords = new String(buf.toString()); // ensure compact string across JDK versions
+ buf = null;
+
+ // intern words at app level via memory-overlaid substrings
+ for (int p=0, j=0; j < size; j++) {
+ String word = words[j];
+ internedWords.put(word, allWords.substring(p, p + word.length()));
+ p += word.length();
+ }
+
+ // replace words with interned words
+ for (int j=0; j < size; j++) {
+ String[] syns = allSynonyms[j];
+ for (int k=syns.length; --k >= 0; ) {
+ syns[k] = internedWords.get(syns[k]);
}
-
- // the following utility methods below are copied from Apache style Nux library - see http://dsd.lbl.gov/nux
- private static byte[] toByteArray(InputStream input) throws IOException {
- try {
- // safe and fast even if input.available() behaves weird or buggy
- int len = Math.max(256, input.available());
- byte[] buffer = new byte[len];
- byte[] output = new byte[len];
-
- len = 0;
- int n;
- while ((n = input.read(buffer)) >= 0) {
- if (len + n > output.length) { // grow capacity
- byte tmp[] = new byte[Math.max(output.length << 1, len + n)];
- System.arraycopy(output, 0, tmp, 0, len);
- System.arraycopy(buffer, 0, tmp, len, n);
- buffer = output; // use larger buffer for future larger bulk reads
- output = tmp;
- } else {
- System.arraycopy(buffer, 0, output, len, n);
- }
- len += n;
- }
-
- if (len == output.length) return output;
- buffer = null; // help gc
- buffer = new byte[len];
- System.arraycopy(output, 0, buffer, 0, len);
- return buffer;
- } finally {
- if (input != null) input.close();
+ word2Syns.remove(words[j]);
+ word2Syns.put(internedWords.get(words[j]), syns);
+ }
+
+ if (DEBUG) {
+ words = null;
+ allSynonyms = null;
+ internedWords = null;
+ allWords = null;
+ System.err.println("before gc");
+ for (int i=0; i < 10; i++) System.gc();
+ System.err.println("after gc");
+ }
+ return word2Syns;
+ }
+
+ // the following utility methods below are copied from Apache style Nux library - see http://dsd.lbl.gov/nux
+ private static byte[] toByteArray(InputStream input) throws IOException {
+ try {
+ // safe and fast even if input.available() behaves weird or buggy
+ int len = Math.max(256, input.available());
+ byte[] buffer = new byte[len];
+ byte[] output = new byte[len];
+
+ len = 0;
+ int n;
+ while ((n = input.read(buffer)) >= 0) {
+ if (len + n > output.length) { // grow capacity
+ byte[] tmp = new byte[Math.max(output.length << 1, len + n)];
+ System.arraycopy(output, 0, tmp, 0, len);
+ System.arraycopy(buffer, 0, tmp, len, n);
+ buffer = output; // use larger buffer for future larger bulk reads
+ output = tmp;
+ } else {
+ System.arraycopy(buffer, 0, output, len, n);
}
+ len += n;
}
-
+
+ if (len == output.length) return output;
+ buffer = null; // help gc
+ buffer = new byte[len];
+ System.arraycopy(output, 0, buffer, 0, len);
+ return buffer;
+ } finally {
+ if (input != null) input.close();
+ }
+ }
}
\ No newline at end of file
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/ParserConstants.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/ParserConstants.java
index 9862ffb..0fbe53e 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/ParserConstants.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/ParserConstants.java
@@ -2,73 +2,73 @@ package opennlp.tools.apps.review_builder;
public interface ParserConstants {
// added new POS types for infinitive phrase and participle phrase
- public static final String TYPE_STP = "STP"; // infinitive phrase
- public static final String TYPE_SGP = "SGP"; // present participle phrase
- public static final String TYPE_SNP = "SNP"; // past participle phrase
+ String TYPE_STP = "STP"; // infinitive phrase
+ String TYPE_SGP = "SGP"; // present participle phrase
+ String TYPE_SNP = "SNP"; // past participle phrase
// below are the standard POS types,
// http://bulba.sdsu.edu/jeanette/thesis/PennTags.html
- public static final String TYPE_ADJP = "ADJP";
- public static final String TYPE_ADVP = "ADVP";
- public static final String TYPE_CC = "CC";
- public static final String TYPE_CD = "CD";
- public static final String TYPE_CONJP = "CONJP";
- public static final String TYPE_DT = "DT";
- public static final String TYPE_EX = "EX";
- public static final String TYPE_FRAG = "FRAG";
- public static final String TYPE_FW = "FW";
- public static final String TYPE_IN = "IN";
- public static final String TYPE_INTJ = "INTJ";
- public static final String TYPE_JJ = "JJ";
- public static final String TYPE_JJR = "JJR";
- public static final String TYPE_JJS = "JJS";
- public static final String TYPE_LS = "LS";
- public static final String TYPE_LST = "LST";
- public static final String TYPE_MD = "MD";
- public static final String TYPE_NAC = "NAC";
- public static final String TYPE_NN = "NN";
- public static final String TYPE_NNS = "NNS";
- public static final String TYPE_NNP = "NNP";
- public static final String TYPE_NNPS = "NNPS";
- public static final String TYPE_NP = "NP";
- public static final String TYPE_NX = "NX";
- public static final String TYPE_PDT = "PDT";
- public static final String TYPE_POS = "POS";
- public static final String TYPE_PP = "PP";
- public static final String TYPE_PRN = "PRN";
- public static final String TYPE_PRP = "PRP";
- public static final String TYPE_PRP$ = "PRP$";
- public static final String TYPE_PRT = "PRT";
- public static final String TYPE_QP = "QP";
- public static final String TYPE_RB = "RB";
- public static final String TYPE_RBR = "RBR";
- public static final String TYPE_RBS = "RBS";
- public static final String TYPE_RP = "RP";
- public static final String TYPE_RRC = "RRC";
- public static final String TYPE_S = "S";
- public static final String TYPE_SBAR = "SBAR";
- public static final String TYPE_SBARQ = "SBARQ";
- public static final String TYPE_SINV = "SINV";
- public static final String TYPE_SQ = "SQ";
- public static final String TYPE_SYM = "SYM";
- public static final String TYPE_TO = "TO";
- public static final String TYPE_TOP = "TOP";
- public static final String TYPE_UCP = "UCP";
- public static final String TYPE_UH = "UH";
- public static final String TYPE_VB = "VB";
- public static final String TYPE_VBD = "VBD";
- public static final String TYPE_VBG = "VBG";
- public static final String TYPE_VBN = "VBN";
- public static final String TYPE_VBP = "VBP";
- public static final String TYPE_VBZ = "VBZ";
- public static final String TYPE_VP = "VP";
- public static final String TYPE_WDT = "WDT";
- public static final String TYPE_WHADJP = "WHADJP";
- public static final String TYPE_WHADVP = "WHADVP";
- public static final String TYPE_WHNP = "WHNP";
- public static final String TYPE_WHPP = "WHPP";
- public static final String TYPE_WP = "WP";
- public static final String TYPE_WP$ = "WP$";
- public static final String TYPE_WRB = "WRB";
- public static final String TYPE_X = "X";
+ String TYPE_ADJP = "ADJP";
+ String TYPE_ADVP = "ADVP";
+ String TYPE_CC = "CC";
+ String TYPE_CD = "CD";
+ String TYPE_CONJP = "CONJP";
+ String TYPE_DT = "DT";
+ String TYPE_EX = "EX";
+ String TYPE_FRAG = "FRAG";
+ String TYPE_FW = "FW";
+ String TYPE_IN = "IN";
+ String TYPE_INTJ = "INTJ";
+ String TYPE_JJ = "JJ";
+ String TYPE_JJR = "JJR";
+ String TYPE_JJS = "JJS";
+ String TYPE_LS = "LS";
+ String TYPE_LST = "LST";
+ String TYPE_MD = "MD";
+ String TYPE_NAC = "NAC";
+ String TYPE_NN = "NN";
+ String TYPE_NNS = "NNS";
+ String TYPE_NNP = "NNP";
+ String TYPE_NNPS = "NNPS";
+ String TYPE_NP = "NP";
+ String TYPE_NX = "NX";
+ String TYPE_PDT = "PDT";
+ String TYPE_POS = "POS";
+ String TYPE_PP = "PP";
+ String TYPE_PRN = "PRN";
+ String TYPE_PRP = "PRP";
+ String TYPE_PRP$ = "PRP$";
+ String TYPE_PRT = "PRT";
+ String TYPE_QP = "QP";
+ String TYPE_RB = "RB";
+ String TYPE_RBR = "RBR";
+ String TYPE_RBS = "RBS";
+ String TYPE_RP = "RP";
+ String TYPE_RRC = "RRC";
+ String TYPE_S = "S";
+ String TYPE_SBAR = "SBAR";
+ String TYPE_SBARQ = "SBARQ";
+ String TYPE_SINV = "SINV";
+ String TYPE_SQ = "SQ";
+ String TYPE_SYM = "SYM";
+ String TYPE_TO = "TO";
+ String TYPE_TOP = "TOP";
+ String TYPE_UCP = "UCP";
+ String TYPE_UH = "UH";
+ String TYPE_VB = "VB";
+ String TYPE_VBD = "VBD";
+ String TYPE_VBG = "VBG";
+ String TYPE_VBN = "VBN";
+ String TYPE_VBP = "VBP";
+ String TYPE_VBZ = "VBZ";
+ String TYPE_VP = "VP";
+ String TYPE_WDT = "WDT";
+ String TYPE_WHADJP = "WHADJP";
+ String TYPE_WHADVP = "WHADVP";
+ String TYPE_WHNP = "WHNP";
+ String TYPE_WHPP = "WHPP";
+ String TYPE_WP = "WP";
+ String TYPE_WP$ = "WP$";
+ String TYPE_WRB = "WRB";
+ String TYPE_X = "X";
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/SentenceOriginalizer.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/SentenceOriginalizer.java
index 1e53d2a..5ad6c53 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/SentenceOriginalizer.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/SentenceOriginalizer.java
@@ -265,11 +265,10 @@ public class SentenceOriginalizer {
}
public static void main(String[] args){
- //ProductFinderInAWebPage init = new ProductFinderInAWebPage("C:/workspace/productsearchfe/src/test/resources");
SentenceOriginalizer orig = new SentenceOriginalizer("src/test/resources");
String[] sents = new String[] {
"Leave the bulky stabilization rig at home and take smooth handheld videos from any angle thanks to Optical SteadyShot image stabilization with Active Mode."
- //"Other then that, it works well, and the chain stops instantly when you let go of the trigger, or push the safety bar."
+ //"Other than that, it works well, and the chain stops instantly when you let go of the trigger, or push the safety bar."
};
String[] res = orig.convert(sents, "VIP Product", "vv propro");
System.out.println(Arrays.asList(res));
@@ -278,7 +277,7 @@ public class SentenceOriginalizer {
}
/*
- * 1. Some Amazon specific text keeps showing up so we might want to put a filter on recurring phrases such as:
+ * 1. Some Amazon specific text keeps showing up, so we might want to put a filter on recurring phrases such as:
1. Unlimited Free Two-Day Shipping
2. View Larger
3. What's in the box
@@ -291,7 +290,7 @@ public class SentenceOriginalizer {
3. Saw some HTML formatting occasionally, such as <em></em>
4. Redundancy with choice phrases appearing multiple times in a single review
5. Specific issue with words being added at the end of the letter "s," creating nonsensical words:
-1. It mispronouncesulphur virtually every caller'sulphur name in waysulphur that..
+1. It mispronouncesulphur virtually every caller'sulphur name in waysulphur that.
2. In fact, it'southward a rare feature that I recollect southwardhould be commonplace in any southwardurround receiver.
6. Adding -iness to make nonsensical words: mightinessiness, powerinessiness
@@ -300,7 +299,7 @@ public class SentenceOriginalizer {
/*
- * After using a gasoline powered chain saw for many years had to stop using because of dust and fumes made my copd worse this electric saw is great has surprising amount of power without the gas fumes..
+ * After using a gasoline powered chain saw for many years had to stop using because of dust and fumes made my copd worse this electric saw is great has surprising amount of power without the gas fumes.
Nice chainsaw, works great, well built.
The instant-stop chain is very safe, but a bit abrupt when releasing the trigger.
I wish there were a half-way release that turned off the motor but did not engage the instant stop break.
@@ -308,7 +307,7 @@ Pros .
inexpensive compared to gas chainsaws, lightweight, cuts with good power, will do most anything that a gas chainsaw will do. like the automatic chain oiler and easy tension adjustment.
Cons .
If you are cutting larger branches and trees, a gas is better.
-However this will work on 8-10" size very well.
+However, this will work on 8-10" size very well.
Bought this McCulloch electric chainsaw to replace an old Craftsman electric chain saw. (the Craftsman got ran over by a car).
Compared to my old Craftsman electric chain saw, the McCulloch seems to be wonderful.
The first test was to cut a 16" diameter oak branch, cut thru it like hot butter.
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/WebPageReviewExtractor.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/WebPageReviewExtractor.java
index de3f5a6..10414b4 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/WebPageReviewExtractor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/review_builder/WebPageReviewExtractor.java
@@ -304,7 +304,7 @@ public class WebPageReviewExtractor extends WebPageExtractor {
int count = 0;
for(String sent:sentences){
if (sent!=null)
- buf.append(sent+" ");
+ buf.append(sent).append(" ");
if (count%2==0 && count<features.length)
if (features[count]!=null){
buf.append(features[count]);
@@ -344,7 +344,7 @@ public class WebPageReviewExtractor extends WebPageExtractor {
int currentRevIndex = 0;
for(String sent:sentences){
if (sent!=null)
- bufs[currentRevIndex].append(sent+" ");
+ bufs[currentRevIndex].append(sent).append(" ");
if (count%2==0 && count<features.length)
if (features[count]!=null){
bufs[currentRevIndex].append(features[count]);
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/EmailSender.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/EmailSender.java
index 92d35d1..9c1ecec 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/EmailSender.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/EmailSender.java
@@ -8,7 +8,7 @@ import javax.mail.internet.*;
import javax.activation.*;
/**
- * Responsible to sending e-mails trough a gmail smtp server.
+ * Responsible to sending e-mails through a gmail smtp server.
* It will be extended to handle arbitrary smtp servers.
* @author GaDo
*
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/SMTP_Authenticator.java b/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/SMTP_Authenticator.java
index cf0a433..3331d90 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/SMTP_Authenticator.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/apps/utils/email/SMTP_Authenticator.java
@@ -3,10 +3,8 @@ import javax.mail.*;
/**
- * This contains the required informations for the smtp authorization!
- *
+ * This contains the required information for the smtp authorization!
*/
-
public class SMTP_Authenticator extends javax.mail.Authenticator {
private String username="bg7550@gmail.com";
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifier.java b/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifier.java
index 95769bd..e5702ce 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifier.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/doc_classifier/DocClassifier.java
@@ -85,7 +85,7 @@ public class DocClassifier {
// for
// classification
private static final int MIN_CHARS_IN_QUERY = 30; // if combination of
- // keywords is shorter,
+ // keywords are shorter,
// should not be used
// for classification
@@ -135,7 +135,7 @@ public class DocClassifier {
return results;
}
- TopDocs hits = null; // TopDocs search(Query query, int n)
+ TopDocs hits = null; // TopDocs search(Query, int)
// Finds the top n hits for query.
try {
hits = indexSearcher
@@ -279,9 +279,7 @@ public class DocClassifier {
String query = formClassifQuery(sentence, MAX_TOKENS_TO_FORM);
classifResults = classifySentence(query);
if (classifResults != null && classifResults.size() > 0) {
- for (String c : classifResults) {
- localCats.add(c);
- }
+ localCats.addAll(classifResults);
logger.debug(sentence + " => " + classifResults);
}
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/enron_email_recognizer/EmailTrainingSetFormer.java b/opennlp-similarity/src/main/java/opennlp/tools/enron_email_recognizer/EmailTrainingSetFormer.java
index 4aabaf6..186dde6 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/enron_email_recognizer/EmailTrainingSetFormer.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/enron_email_recognizer/EmailTrainingSetFormer.java
@@ -54,7 +54,7 @@ public class EmailTrainingSetFormer {
}
}
if (bAccept)
- buf.append(l+"\n");
+ buf.append(l).append("\n");
}
return buf.toString();
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/fca/BasicLevelMetrics.java b/opennlp-similarity/src/main/java/opennlp/tools/fca/BasicLevelMetrics.java
index dea7e7d..2540388 100755
--- a/opennlp-similarity/src/main/java/opennlp/tools/fca/BasicLevelMetrics.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/fca/BasicLevelMetrics.java
@@ -347,7 +347,7 @@ public class BasicLevelMetrics {
public double lowerCohAvgByAvgJ(FormalConcept c,float tetta){
double sum = 0;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
int rightNeighborsNumber = 0;
float truthDegree;
for (Integer i: lowerNeighbors){
@@ -369,7 +369,7 @@ public class BasicLevelMetrics {
double sum = 0;
int rightNeighborsNumber = 0;
float truthDegree;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
for (Integer i: lowerNeighbors){
if (c.cohMinJ< cl.conceptList.get(i).cohMinJ){
rightNeighborsNumber++;
@@ -390,7 +390,7 @@ public class BasicLevelMetrics {
double min = Integer.MAX_VALUE, val;
int rightNeighborsNumber = 0;
float truthDegree;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
for (Integer i: lowerNeighbors){
if (c.cohAvgJ< cl.conceptList.get(i).cohAvgJ){
rightNeighborsNumber++;
@@ -412,7 +412,7 @@ public class BasicLevelMetrics {
double min = Integer.MAX_VALUE, val;
int rightNeighborsNumber = 0;
float truthDegree;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
for (Integer i: lowerNeighbors){
if (c.cohMinJ< cl.conceptList.get(i).cohMinJ){
rightNeighborsNumber++;
@@ -434,7 +434,7 @@ public class BasicLevelMetrics {
double sum = 0;
int rightNeighborsNumber = 0;
float truthDegree;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
for (Integer i: lowerNeighbors){
if (c.cohAvgSMC < cl.conceptList.get(i).cohAvgSMC){
rightNeighborsNumber++;
@@ -454,7 +454,7 @@ public class BasicLevelMetrics {
double sum = 0;
int rightNeighborsNumber = 0;
float truthDegree;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
for (Integer i: lowerNeighbors){
if (c.cohMinSMC < cl.conceptList.get(i).cohMinSMC){
rightNeighborsNumber++;
@@ -474,7 +474,7 @@ public class BasicLevelMetrics {
double min = Integer.MAX_VALUE, val;
int rightNeighborsNumber = 0;
float truthDegree;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
for (Integer i: lowerNeighbors){
if (c.cohAvgSMC<=cl.conceptList.get(i).cohAvgSMC){
rightNeighborsNumber++;
@@ -497,7 +497,7 @@ public class BasicLevelMetrics {
double min = Integer.MAX_VALUE, val;
int rightNeighborsNumber = 0;
float truthDegree;
- Set<Integer> lowerNeighbors =c.childs;
+ Set<Integer> lowerNeighbors =c.children;
for (Integer i: lowerNeighbors){
if (c.cohMinSMC< cl.conceptList.get(i).cohMinSMC){
rightNeighborsNumber++;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/fca/ConceptLattice.java b/opennlp-similarity/src/main/java/opennlp/tools/fca/ConceptLattice.java
index dad91c7..ccb307d 100755
--- a/opennlp-similarity/src/main/java/opennlp/tools/fca/ConceptLattice.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/fca/ConceptLattice.java
@@ -163,16 +163,16 @@ public class ConceptLattice {
newConcept.setPosition(conceptList.size());
conceptList.add(newConcept);
conceptList.get(generator).getParents().add(newConcept.position);
- conceptList.get(newConcept.position).childs.add(generator);
+ conceptList.get(newConcept.position).children.add(generator);
for (int newParent: newParents) {
if (conceptList.get(generator).getParents().contains(newParent)) {
conceptList.get(generator).getParents().remove(newParent);
- conceptList.get(newParent).childs.remove(generator);
+ conceptList.get(newParent).children.remove(generator);
}
conceptList.get(newConcept.position).getParents().add(newParent);
conceptList.get(newParent).addExtents(new_extent);
AddExtentToAncestors(new_extent, newParent);
- conceptList.get(newParent).childs.add(newConcept.position);
+ conceptList.get(newParent).children.add(newConcept.position);
}
return newConcept.position;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/fca/FcaConverter.java b/opennlp-similarity/src/main/java/opennlp/tools/fca/FcaConverter.java
index 6fc90b5..d8cc3af 100755
--- a/opennlp-similarity/src/main/java/opennlp/tools/fca/FcaConverter.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/fca/FcaConverter.java
@@ -30,8 +30,7 @@ public class FcaConverter {
int newAttrCount = cl.conceptList.size();
int [][] binaryContext = null;
- ArrayList<FormalConcept> cList = new ArrayList<FormalConcept>();
- cList.addAll(cl.conceptList);
+ ArrayList<FormalConcept> cList = new ArrayList<FormalConcept>(cl.conceptList);
boolean run = true;
int k=0;
while (run && k<cl.conceptList.size()){
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/fca/FormalConcept.java b/opennlp-similarity/src/main/java/opennlp/tools/fca/FormalConcept.java
index a97917d..1b827ad 100755
--- a/opennlp-similarity/src/main/java/opennlp/tools/fca/FormalConcept.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/fca/FormalConcept.java
@@ -25,7 +25,7 @@ import java.util.Set;
public class FormalConcept {
int position;
ArrayList<Integer>intent;
- Set<Integer> childs;
+ Set<Integer> children;
Set<Integer> parents;
Set<Integer> extent;
double intLogStabilityBottom = 0,
@@ -56,7 +56,7 @@ public class FormalConcept {
intent = new ArrayList<Integer>();
extent = new LinkedHashSet<Integer>();
parents = new HashSet<Integer>();
- childs = new HashSet<Integer>();
+ children = new HashSet<Integer>();
}
public void setPosition(int newPosition ){
@@ -76,13 +76,13 @@ public class FormalConcept {
intent.addAll(newIntent);
}
- public void setChilds(Set<Integer> newChilds ){
- childs.clear();
- childs.addAll(newChilds);
+ public void setChildren(Set<Integer> newChilds ){
+ children.clear();
+ children.addAll(newChilds);
}
public void addChild(Integer child ){
- childs.add(child);
+ children.add(child);
}
public void setParents( Set<Integer> newParents ){
@@ -96,7 +96,7 @@ public class FormalConcept {
System.out.println("Concept intent:" + getIntent());
System.out.println("Concept extent:" + extent);
System.out.println("Concept parents:" + getParents());
- System.out.println("Concept childs:" + childs);
+ System.out.println("Concept children:" + children);
System.out.println("--------------------");
}
@@ -105,7 +105,7 @@ public class FormalConcept {
System.out.println("Concept intent:" + getIntent());
System.out.println("Concept extent:" + extent);
System.out.println("Concept parents:" + getParents());
- System.out.println("Concept childs:" + childs);
+ System.out.println("Concept children:" + children);
System.out.format("Prob. blSaaJ blSaaSMC blSmaJ blSmmJ blSmaSMC blSamJ blSamSMC blCV blCFC blCU blP separ.\n");
System.out.format("%5.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", probability, blS_Jaa, blS_SMCaa,
blS_Jma, blS_Jmm, blS_SMCma, blS_Jam, blS_SMCam, blCV, blCFC, blCU, blP, separation);
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/fca/Measures.java b/opennlp-similarity/src/main/java/opennlp/tools/fca/Measures.java
index 747578e..e65618d 100755
--- a/opennlp-similarity/src/main/java/opennlp/tools/fca/Measures.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/fca/Measures.java
@@ -55,8 +55,7 @@ public class Measures {
min_delta = cl.attributeCount;
sum = 0;
FormalConcept fc = cl.conceptList.get(i);
- Set<Integer> childs = fc.childs;
- for (Integer j: childs) {
+ for (Integer j: fc.children) {
delta = fc.getExtent().size() - cl.conceptList.get(j).getExtent().size();
if (delta<min_delta)
min_delta = delta;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/IntersectionSetBuilder.java b/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/IntersectionSetBuilder.java
index 25232b7..b4c6d99 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/IntersectionSetBuilder.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/IntersectionSetBuilder.java
@@ -229,7 +229,7 @@ public class IntersectionSetBuilder{
}
if (countCoverNeg<2){
- System.err.println("A rule formed but it does not cover its origin! "+intersection);
+ System.err.println("A rule formed, but it does not cover its origin! "+intersection);
distProcessorNeg.ruleCoversCase(intersection, negativeSet.get(i));
distProcessorNeg.ruleCoversCase(intersection, negativeSet.get(j));
} */
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/ProfileReaderWriter.java b/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/ProfileReaderWriter.java
index 1ba6aac..298ade9 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/ProfileReaderWriter.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/ProfileReaderWriter.java
@@ -21,6 +21,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import au.com.bytecode.opencsv.CSVReader;
@@ -57,9 +58,7 @@ public class ProfileReaderWriter {
public static void writeReportArr( String[][] allLines, String reportName){
List<String[]> rep = new ArrayList<String[]>();
- for(String[] line: allLines){
- rep.add(line);
- }
+ rep.addAll(Arrays.asList(allLines));
writeReport( rep, reportName);
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/TreeKernelRunner.java b/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/TreeKernelRunner.java
index 328fc10..58ca03b 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/TreeKernelRunner.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/jsmlearning/TreeKernelRunner.java
@@ -64,7 +64,7 @@ public class TreeKernelRunner {
runEXE(runString, dir);
}
- class StreamLogger extends Thread{
+ static class StreamLogger extends Thread{
private InputStream mInputStream;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/ParseTreeNode.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/ParseTreeNode.java
index 0dbb192..59cad3b 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/ParseTreeNode.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/ParseTreeNode.java
@@ -137,13 +137,13 @@ public class ParseTreeNode implements IGeneralizer<ParseTreeNode>{
public String toString(){
StringBuffer buf = new StringBuffer();
if (id!=null)
- buf.append("<"+id+">");
+ buf.append("<").append(id).append(">");
if(phraseType!=null)
buf.append(phraseType);
if(word!=null)
- buf.append("'"+word+"'");
+ buf.append("'").append(word).append("'");
if (pos!=null)
- buf.append(":"+pos);
+ buf.append(":").append(pos);
return buf.toString();
}
@@ -152,7 +152,7 @@ public class ParseTreeNode implements IGeneralizer<ParseTreeNode>{
for(ParseTreeNode ch: chList){
if (ch.getPos().startsWith(".") || ch.getPos().startsWith(",") || ch.getPos().startsWith(";") || ch.getPos().startsWith("!"))
continue;
- buf.append( "("+ch.getWord()+ " " + ch.getPos() + ")" );
+ buf.append("(").append(ch.getWord()).append(" ").append(ch.getPos()).append(")");
}
return buf.toString().trim();
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java
index 62fd53c..abd5b90 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/VerbNetProcessor.java
@@ -157,37 +157,37 @@ public class VerbNetProcessor implements IGeneralizer<Map<String, List<String>>>
}
// takes a verb and forms its verbnet parameters
- // abandon (leave-51.2 leave-51.2 ) (NP V NP.source ) (Transitivebasically, locative preposition drop of "from" ) (
+ // abandon (leave-51.2 leave-51.2 ) (NP V NP.source ) (Transitive basically, locative preposition drop of "from" ) (
public StringBuilder buildTreeRepresentationForTreeKernelLearning(String verb){
StringBuilder sb = new StringBuilder(1000);
IVerbClass v;
v = getVerbNetForAVerb(verb);
if (v==null) // for some reason this verb is not in the vocabulary
return null;
- sb.append(verb + " (" );
+ sb.append(verb).append(" (");
List<IThematicRole> roles = v.getThematicRoles();
for(int i=0; i< roles.size(); i++){
- sb.append(roles.get(i).getVerbClass().getID().replace(".", "")+" ");
+ sb.append(roles.get(i).getVerbClass().getID().replace(".", "")).append(" ");
}
sb.append( ") (" );
List<IFrame> frames = v.getFrames();
for(int i=0; i< frames.size(); i++){
- sb.append(//" ("+
- frames.get(i).getPrimaryType().getID().replace(".", "-")+" ");
+ //" ("+
+ sb.append(frames.get(i).getPrimaryType().getID().replace(".", "-")).append(" ");
}
sb.append( ") (" );
for(int i=0; i< frames.size(); i++){
sb.append(frames.get(i).getSecondaryType().getID().
- replace(".", "").replace(",", " ").replace("\"", "-").replace("/", "-").replace("(","").replace(")","")+" ");
+ replace(".", "").replace(",", " ").replace("\"", "-").replace("/", "-").replace("(", "").replace(")", "")).append(" ");
}
sb.append( ") " );
if (v.getParent()!=null && v.getParent().getThematicRoles()!=null){
sb.append( "(" );
for(int i=0; i<v.getParent().getThematicRoles().size(); i++){
- sb.append(v.getParent().getThematicRoles().get(i).getType()+" ");
+ sb.append(v.getParent().getThematicRoles().get(i).getType()).append(" ");
}
sb.append( ")" );
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/MostFrequentWordsFromPageGetter.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/MostFrequentWordsFromPageGetter.java
index bc4d366..0e937f5 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/MostFrequentWordsFromPageGetter.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/MostFrequentWordsFromPageGetter.java
@@ -20,9 +20,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Scanner;
-import java.util.TreeMap;
import org.apache.commons.lang.StringUtils;
@@ -30,13 +28,11 @@ import opennlp.tools.similarity.apps.utils.ValueSortMap;
public class MostFrequentWordsFromPageGetter {
- public List<String> getMostFrequentWordsInText(String input)
- {
+ public List<String> getMostFrequentWordsInText(String input) {
int maxRes = 4;
Scanner in = new Scanner(input);
in.useDelimiter("\\s+");
- Map<String, Integer> words =
- new HashMap<String, Integer>();
+ Map<String, Integer> words = new HashMap<>();
while (in.hasNext()) {
String word = in.next();
@@ -51,15 +47,16 @@ public class MostFrequentWordsFromPageGetter {
}
words = ValueSortMap.sortMapByValue(words, false);
- List<String> results = new ArrayList<String>(words.keySet());
+ List<String> results = new ArrayList<>(words.keySet());
if (results.size() > maxRes )
results = results.subList(0, maxRes); // get maxRes elements
- return results;
- }
+ return results;
+ }
+
public List<String> getMostFrequentWordsInTextArr(String[] longestSents) {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
for(String s: longestSents){
buffer.append(s);
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/SnippetToParagraph.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/SnippetToParagraph.java
index 4e9de23..9558450 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/SnippetToParagraph.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/SnippetToParagraph.java
@@ -59,8 +59,7 @@ public class SnippetToParagraph extends ContentGeneratorSupport /*RelatedSentenc
String snapshotMarked = snapshot.replace("...",
" _should_find_orig_ . _should_find_orig_");
List<String> fragments = TextProcessor.splitToSentences(snapshotMarked);
- List<String> allFragms = new ArrayList<String>();
- allFragms.addAll(fragments);
+ List<String> allFragms = new ArrayList<String>(fragments);
List<String> sents = new ArrayList<String>();
String downloadedPage;
@@ -348,7 +347,7 @@ public class SnippetToParagraph extends ContentGeneratorSupport /*RelatedSentenc
}
return results;
}
- public class TextChunk {
+ public static class TextChunk {
public TextChunk(String s, int length) {
this.text = s;
this.len = length;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/WebPageExtractor.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/WebPageExtractor.java
index 8535fc0..75c0013 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/WebPageExtractor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/apps/WebPageExtractor.java
@@ -125,7 +125,7 @@ public class WebPageExtractor {
return sentsClean.toArray(new String[0]);
}
- public class TextChunk {
+ public static class TextChunk {
public TextChunk(String s, int length) {
this.text = s;
this.len = length;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/NERPhraseGeneralizer.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/NERPhraseGeneralizer.java
index 80c75e8..9e82389 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/NERPhraseGeneralizer.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/NERPhraseGeneralizer.java
@@ -21,27 +21,13 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-
-
-
-
-
-
-
-
-
-import opennlp.tools.parse_thicket.IGeneralizer;
import opennlp.tools.parse_thicket.ParseTreeNode;
-import opennlp.tools.stemmer.PStemmer;
-import opennlp.tools.textsimilarity.GeneralizationListReducer;
-import opennlp.tools.textsimilarity.LemmaFormManager;
-import opennlp.tools.textsimilarity.POSManager;
import opennlp.tools.textsimilarity.ParseTreeChunk;
public class NERPhraseGeneralizer extends PhraseGeneralizer {
- /* alignment is based on NER values, not on POS now
- *
+ /*
+ * alignment is based on NER values, not on POS now
*/
@@ -49,8 +35,8 @@ public class NERPhraseGeneralizer extends PhraseGeneralizer {
* key matching function which takes two phrases, aligns them and finds a set
* of maximum common sub-phrase
*
- * @param chunk1
- * @param chunk2
+ * @param chunk1o
+ * @param chunk2o
* @return
*/
@Override
@@ -240,7 +226,7 @@ public class NERPhraseGeneralizer extends PhraseGeneralizer {
// behind
// current
// position,
- // synchroneously
+ // synchronously
// move
// towards
// right
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/PhraseGeneralizer.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/PhraseGeneralizer.java
index 1dbc78e..61ef397 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/PhraseGeneralizer.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/matching/PhraseGeneralizer.java
@@ -20,26 +20,17 @@ package opennlp.tools.parse_thicket.matching;
import java.util.ArrayList;
import java.util.List;
-
-
-
-
-
import opennlp.tools.parse_thicket.IGeneralizer;
import opennlp.tools.parse_thicket.ParseTreeNode;
import opennlp.tools.stemmer.PStemmer;
import opennlp.tools.textsimilarity.GeneralizationListReducer;
-import opennlp.tools.textsimilarity.LemmaFormManager;
-import opennlp.tools.textsimilarity.POSManager;
import opennlp.tools.textsimilarity.ParseTreeChunk;
public class PhraseGeneralizer implements IGeneralizer<ParseTreeChunk> {
- private GeneralizationListReducer generalizationListReducer = new GeneralizationListReducer();
+ private final GeneralizationListReducer generalizationListReducer = new GeneralizationListReducer();
protected LemmaGeneralizer lemmaFormManager = new LemmaGeneralizer();
- //protected LemmaFormManager lemmaFormManager = new LemmaFormManager();
-
-
+
protected PartOfSpeechGeneralizer posManager = new PartOfSpeechGeneralizer();
protected PStemmer ps = new PStemmer();
@@ -49,8 +40,8 @@ public class PhraseGeneralizer implements IGeneralizer<ParseTreeChunk> {
* key matching function which takes two phrases, aligns them and finds a set
* of maximum common sub-phrase
*
- * @param chunk1
- * @param chunk2
+ * @param chunk1o
+ * @param chunk2o
* @return
*/
@Override
@@ -70,7 +61,6 @@ public class PhraseGeneralizer implements IGeneralizer<ParseTreeChunk> {
List<String> lem1stem = new ArrayList<String>();
List<String> lem2stem = new ArrayList<String>();
-
for (String word : lem1) {
try {
lem1stem.add(ps.stem(word.toLowerCase()).toString());
@@ -237,7 +227,7 @@ public class PhraseGeneralizer implements IGeneralizer<ParseTreeChunk> {
// behind
// current
// position,
- // synchroneously
+ // synchronously
// move
// towards
// right
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/LinguisticPatternStructure.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/LinguisticPatternStructure.java
index 9b97b59..6ddca1e 100755
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/LinguisticPatternStructure.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/LinguisticPatternStructure.java
@@ -106,16 +106,16 @@ public class LinguisticPatternStructure extends PhrasePatternStructure {
newConcept.setPosition(conceptList.size());
conceptList.add(newConcept);
conceptList.get(generator).parents.add(newConcept.position);
- conceptList.get(newConcept.position).childs.add(generator);
+ conceptList.get(newConcept.position).children.add(generator);
for (int newParent: newParents) {
if (conceptList.get(generator).parents.contains(newParent)) {
conceptList.get(generator).parents.remove(newParent);
- conceptList.get(newParent).childs.remove(generator);
+ conceptList.get(newParent).children.remove(generator);
}
conceptList.get(newConcept.position).parents.add(newParent);
conceptList.get(newParent).addExtents(new_extent);
AddExtentToAncestors(new_extent, newParent);
- conceptList.get(newParent).childs.add(newConcept.position);
+ conceptList.get(newParent).children.add(newConcept.position);
}
return newConcept.position;
}
@@ -135,8 +135,7 @@ public class LinguisticPatternStructure extends PhrasePatternStructure {
public int [][] toContext(int extentCardinality){
int newAttrCount = conceptList.size();
- ArrayList<PhraseConcept> cList = new ArrayList<PhraseConcept>();
- cList.addAll(conceptList);
+ ArrayList<PhraseConcept> cList = new ArrayList<>(conceptList);
boolean run = true;
int k=0;
while (run && k<conceptList.size()){
@@ -175,18 +174,17 @@ public class LinguisticPatternStructure extends PhrasePatternStructure {
public void logStability(){
int min_delta = -1, delta = -1;
float sum = 0;
- for (int i = 0; i < conceptList.size(); ++i) {
+ for (PhraseConcept phraseConcept : conceptList) {
min_delta = Integer.MAX_VALUE;
sum = 0;
- PhraseConcept pc = conceptList.get(i);
- Set<Integer> childs = pc.childs;
- for (Integer j: childs) {
+ PhraseConcept pc = phraseConcept;
+ for (Integer j : pc.children) {
delta = pc.extent.size() - conceptList.get(j).extent.size();
- if (delta<min_delta)
+ if (delta < min_delta)
min_delta = delta;
sum += Math.pow(2, -delta);
}
- pc.intLogStabilityBottom=-(Math.log(sum)/Math.log(2.0));
+ pc.intLogStabilityBottom = -(Math.log(sum) / Math.log(2.0));
pc.intLogStabilityUp = min_delta;
}
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/PhraseConcept.java b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/PhraseConcept.java
index 29619cb..49adb6e 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/PhraseConcept.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/parse_thicket/pattern_structure/PhraseConcept.java
@@ -16,18 +16,20 @@
*/
package opennlp.tools.parse_thicket.pattern_structure;
-import java.util.*;
-import java.io.*;
-import opennlp.tools.fca.FormalConcept;
import opennlp.tools.textsimilarity.ParseTreeChunk;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
public class PhraseConcept {
int position;
public List<List<ParseTreeChunk>> intent;
Set<Integer> parents;
- Set<Integer> childs;
+ Set<Integer> children;
Set<Integer> extent;
double intLogStabilityBottom = 0;
@@ -36,23 +38,27 @@ public class PhraseConcept {
public PhraseConcept() {
position = -1;
- intent = new ArrayList<List<ParseTreeChunk>>();
- parents = new HashSet<Integer>();
- extent = new HashSet<Integer>();
- childs = new HashSet<Integer>();
+ intent = new ArrayList<>();
+ parents = new HashSet<>();
+ extent = new HashSet<>();
+ children = new HashSet<>();
}
+
public void setPosition( int newPosition ){
position = newPosition;
}
+
public void setIntent( List<List<ParseTreeChunk>> newIntent ){
intent.clear();
intent.addAll(newIntent);
}
+
public void setParents( Set<Integer> newParents ){
//parents = newParents;
parents.clear();
parents.addAll(newParents);
}
+
public void printConcept() {
System.out.println("Concept position:" + position);
System.out.println("Concept intent:" + intent);
@@ -64,15 +70,14 @@ public class PhraseConcept {
System.out.println("Concept intent:" + intent);
System.out.println("Concept extent:" + extent);
System.out.println("Concept parents:" + parents);
- System.out.println("Concept parents:" + childs);
+ System.out.println("Concept parents:" + children);
System.out.println("log stab: ["+ intLogStabilityBottom + "; "+intLogStabilityUp+"]");
}
public void addExtents(LinkedHashSet<Integer> ext){
extent.addAll(ext);
}
-
-
+
public static void main(String []args) {
PhraseConcept c = new PhraseConcept();
c.printConcept();
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGenerator.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGenerator.java
index cd6b535..e61a379 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGenerator.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGenerator.java
@@ -144,7 +144,7 @@ public class ContentGenerator /*extends RelatedSentenceFinder*/ {
for (String w : qs) {
if (w.toLowerCase().equals(w)) // idf only two words then
// has to be person name,
- // title or geo location
+ // title or geolocation
bAccept = false;
}
if (!bAccept)
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGeneratorSupport.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGeneratorSupport.java
index b2bb840..ad33001 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGeneratorSupport.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/ContentGeneratorSupport.java
@@ -47,8 +47,7 @@ public class ContentGeneratorSupport {
* general (irrelevant search results) or too specific (too few search
* results)
*
- * @param String
- * input sentence to form queries
+ * @param sentence The input sentence to form queries
* @return List<String> of search expressions
*/
public static List<String> buildSearchEngineQueryFromSentence(String sentence) {
@@ -80,7 +79,7 @@ public class ContentGeneratorSupport {
for (String w : qs) {
if (w.toLowerCase().equals(w)) // idf only two words then
// has to be person name,
- // title or geo location
+ // title or geolocation
bAccept = false;
}
if (!bAccept)
@@ -149,8 +148,7 @@ public class ContentGeneratorSupport {
* remove dupes from queries to easy cleaning dupes and repetitive search
* afterwards
*
- * @param List
- * <String> of sentences (search queries, or search results
+ * @param hits A List<String> of sentences (search queries, or search results
* abstracts, or titles
* @return List<String> of sentences where dupes are removed
*/
@@ -194,17 +192,13 @@ public class ContentGeneratorSupport {
/**
* remove dupes from search results
*
- * @param List
- * <HitBase> of search results objects
+ * @param hits A List<HitBase> of search results objects
* @return List<String> of search results objects where dupes are removed
*/
- public static List<HitBase> removeDuplicatesFromResultantHits(
- List<HitBase> hits) {
+ public static List<HitBase> removeDuplicatesFromResultantHits(List<HitBase> hits) {
StringDistanceMeasurer meas = new StringDistanceMeasurer();
double dupeThresh = // 0.8; // if more similar, then considered dupes was
0.7;
- List<Integer> idsToRemove = new ArrayList<>();
- List<HitBase> hitsDedup = new ArrayList<>();
try {
for (int i = 0; i < hits.size(); i++)
for (int j = i + 1; j < hits.size(); j++) {
@@ -346,7 +340,7 @@ public class ContentGeneratorSupport {
return sents;
}
- public class TextChunk {
+ public static class TextChunk {
public TextChunk(String s, int length) {
this.text = s;
this.len = length;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/HitBase.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/HitBase.java
index 989b8fe..0a2de46 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/HitBase.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/HitBase.java
@@ -171,9 +171,9 @@ public class HitBase {
String fragm = (hit.toString());
if (fragm.length() > 15) {
if (pBreak)
- buf.append(fragm + " | ");
+ buf.append(fragm).append(" | ");
else
- buf.append(fragm + " | \n");
+ buf.append(fragm).append(" | \n");
// switch to opposite
if (pBreak)
pBreak = false;
@@ -195,9 +195,9 @@ public class HitBase {
String fragm = hit.getFragments().toString();
if (fragm.length() > 15) {
if (pBreak)
- buf.append(fragm + " | ");
+ buf.append(fragm).append(" | ");
else
- buf.append(fragm + " | <br>\n");
+ buf.append(fragm).append(" | <br>\n");
// switch to opposite
if (pBreak)
pBreak = false;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinder.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinder.java
index e3bc6b6..f513a91 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinder.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinder.java
@@ -25,6 +25,8 @@ import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
+import org.apache.commons.lang.StringUtils;
+
import opennlp.tools.parse_thicket.Triple;
import opennlp.tools.similarity.apps.utils.PageFetcher;
import opennlp.tools.similarity.apps.utils.StringDistanceMeasurer;
@@ -35,18 +37,15 @@ import opennlp.tools.textsimilarity.SentencePairMatchResult;
import opennlp.tools.textsimilarity.TextProcessor;
import opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor;
-import org.apache.commons.lang.StringUtils;
-
-/*
- * This class does content generation by using web mining and syntactic generalization to get sentences from the web, convert and combine them in the form
- * expected to be readable by humans.
- *
+/**
+ * Provides content generation by using web mining and syntactic generalization to get sentences from the web,
+ * convert and combine them in the form expected to be readable by humans.
+ * <p>
* These are examples of generated articles, given the article title
* http://www.allvoices.com/contributed-news/9423860/content/81937916-ichie-sings-jazz-blues-contemporary-tunes
* http://www.allvoices.com/contributed-news/9415063-britney-spears-femme-fatale-in-north-sf-bay-area
*
*/
-
public class RelatedSentenceFinder {
private static final Logger LOG = Logger.getLogger("opennlp.tools.similarity.apps.RelatedSentenceFinder");
PageFetcher pFetcher = new PageFetcher();
@@ -216,7 +215,7 @@ public class RelatedSentenceFinder {
for (String w : qs) {
if (w.toLowerCase().equals(w)) // idf only two words then
// has to be person name,
- // title or geo location
+ // title or geolocation
bAccept = false;
}
if (!bAccept)
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinderML.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinderML.java
index 9ec5539..03b100d 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinderML.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/RelatedSentenceFinderML.java
@@ -21,17 +21,15 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
+
import opennlp.tools.similarity.apps.utils.Utils;
import opennlp.tools.textsimilarity.TextProcessor;
-/*
+/**
* This class does content generation in ES, DE etc
- *
*/
-
public class RelatedSentenceFinderML extends RelatedSentenceFinder{
- private static Logger LOG = Logger
- .getLogger("opennlp.tools.similarity.apps.RelatedSentenceFinderML");
+ private static final Logger LOG = Logger.getLogger("opennlp.tools.similarity.apps.RelatedSentenceFinderML");
public RelatedSentenceFinderML(int ms, int msr, float thresh, String key) {
@@ -74,16 +72,11 @@ public class RelatedSentenceFinderML extends RelatedSentenceFinder{
* to be written and forms essey sentences from the title, abstract, and
* possibly original page
*
- * @param HitBase
- * item : search result
- * @param originalSentence
- * : seed for the essay to be written
- * @param sentsAll
- * : list<String> of other sentences in the seed if it is
- * multi-sentence
+ * @param item The search result
+ * @param originalSentence The seed for the essay to be written
+ * @param sentsAll A list<String> of other sentences in the seed if it is multi-sentence
* @return search result
*/
-
public HitBase augmentWithMinedSentencesAndVerifyRelevance(HitBase item,
String originalSentence, List<String> sentsAll) {
if (sentsAll == null)
@@ -106,8 +99,7 @@ public class RelatedSentenceFinderML extends RelatedSentenceFinder{
String snapshotMarked = snapshot.replace("...",
" _should_find_orig_ . _should_find_orig_");
String[] fragments = sm.splitSentences(snapshotMarked);
- List<String> allFragms = new ArrayList<String>();
- allFragms.addAll(Arrays.asList(fragments));
+ List<String> allFragms = new ArrayList<String>(Arrays.asList(fragments));
String[] sents = null;
String downloadedPage = null;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessor.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessor.java
index ec2a2a8..28df9a7 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessor.java
@@ -36,7 +36,7 @@ public class SpeechRecognitionResultsProcessor /*extends BingWebQueryRunner*/ {
/**
* Gets an expression and tries to find it on the web. If search results are
* syntactically similar to this phrase, then we conclude that this phrase is
- * meaningful (makes sense, someone have said something similar. If search
+ * meaningful (makes sense), someone have said something similar. If search
* results ate not similar to this phrase, we conclude that the phrase is
* meaningless (does not make sense, nobody has ever said something like that)
*
@@ -120,7 +120,7 @@ public class SpeechRecognitionResultsProcessor /*extends BingWebQueryRunner*/ {
}
- public class SentenceMeaningfullnessScore {
+ public static class SentenceMeaningfullnessScore {
String sentence;
double score;
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java
index efeac46..ad4bdda 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/WebSearchEngineResultsScraper.java
@@ -119,7 +119,7 @@ public class WebSearchEngineResultsScraper {
hit.setTitle(title);
results.add(hit);
} catch (Exception e) {
- //problem parsing SERP page; source - specific problem so we swallow exceptions here
+ //problem parsing SERP page; source - specific problem, so we swallow exceptions here
}
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/ContentGeneratorRequestHandler.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/ContentGeneratorRequestHandler.java
index a916a3d..08091ec 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/ContentGeneratorRequestHandler.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/ContentGeneratorRequestHandler.java
@@ -209,7 +209,7 @@ public class ContentGeneratorRequestHandler extends SearchHandler {
try {
file = new File(absPath+"/written/"+ title.replace(' ','_').replace('\"', ' ').trim()+ ".txt");
- // if file doesnt exists, then create it
+ // if file doesn't exist, then create it
if (!file.exists()) {
file.createNewFile();
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeQueryComponent.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeQueryComponent.java
index b4ffe74..b719e70 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeQueryComponent.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeQueryComponent.java
@@ -39,7 +39,7 @@ public class IterativeQueryComponent extends QueryComponent{
public static final String[] fieldSequence = new String[]{"cat", "name", "content", "author"};
/**
- * Run the query multiple times againts various fields, trying to recognize search intention
+ * Run the query multiple times against various fields, trying to recognize search intention
*/
@Override
public void process(ResponseBuilder rb) throws IOException {
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeSearchRequestHandler.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeSearchRequestHandler.java
index 7169b6f..2e75a51 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeSearchRequestHandler.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/IterativeSearchRequestHandler.java
@@ -324,7 +324,7 @@ public class IterativeSearchRequestHandler extends SearchHandler {
}
}
public class PairComparable implements Comparator<Pair> {
- // @Override
+ @Override
public int compare(Pair o1, Pair o2) {
int b = -2;
if ( o1.getSecond() instanceof Float && o2.getSecond() instanceof Float){
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/SearchResultsReRankerRequestHandler.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/SearchResultsReRankerRequestHandler.java
index d11ace1..de81497 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/SearchResultsReRankerRequestHandler.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/SearchResultsReRankerRequestHandler.java
@@ -129,7 +129,7 @@ public class SearchResultsReRankerRequestHandler extends SearchHandler {
StringBuilder buf = new StringBuilder();
buf.append("<scores>");
for(HitBase hit: reRankedResults){
- buf.append("<score index=\""+hit.getSource()+"\">"+hit.getGenerWithQueryScore()+"</score>");
+ buf.append("<score index=\"").append(hit.getSource()).append("\">").append(hit.getGenerWithQueryScore()).append("</score>");
}
buf.append("</scores>");
@@ -141,7 +141,7 @@ public class SearchResultsReRankerRequestHandler extends SearchHandler {
StringBuffer bufNums = new StringBuffer();
bufNums.append("order>");
for(HitBase hit: reRankedResults){
- bufNums.append(hit.getSource()+"_");
+ bufNums.append(hit.getSource()).append("_");
}
bufNums.append("/order>");
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java
index d267cce..1b9097a 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilder.java
@@ -56,7 +56,7 @@ public class WordDocBuilder{
public String buildWordDoc(List<HitBase> content, String title){
- String outputDocFinename = absPath+"/written/"+ title.replace(' ','_').replace('\"', ' ').trim()+ ".docx";
+ String outputDocFilename = absPath+"/written/"+ title.replace(' ','_').replace('\"', ' ').trim()+ ".docx";
WordprocessingMLPackage wordMLPackage;
try {
@@ -78,12 +78,12 @@ public class WordDocBuilder{
//byte[] bytes = convertImageToByteArray(file);
//addImageToPackage(wordMLPackage, bytes);
- wordMLPackage.save(new File(outputDocFinename));
+ wordMLPackage.save(new File(outputDocFilename));
} catch (Exception e) {
e.printStackTrace();
}
- return outputDocFinename;
+ return outputDocFilename;
}
private void addImageByImageTitleToPackage(
@@ -117,8 +117,8 @@ public class WordDocBuilder{
* there is also a method, which takes a filename hint, an alt-text, two ids
* and an indication on whether it should be embedded or linked to.
* One id is for the drawing object non-visual properties of the document, and
- * the second id is for the non visual drawing properties of the picture itself.
- * Finally we add this inline object to the paragraph and the paragraph to the
+ * the second id is for the non-visual drawing properties of the picture itself.
+ * Finally, we add this inline object to the paragraph and the paragraph to the
* main document of the package.
*
* @param wordMLPackage The package we want to add the image to
@@ -145,7 +145,7 @@ public class WordDocBuilder{
/**
* We create an object factory and use it to create a paragraph and a run.
* Then we add the run to the paragraph. Next we create a drawing and
- * add it to the run. Finally we add the inline object to the drawing and
+ * add it to the run. Finally, we add the inline object to the drawing and
* return the paragraph.
*
* @param inline The inline object containing the image.
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderEndNotes.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderEndNotes.java
index ef7b519..3791ab4 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderEndNotes.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderEndNotes.java
@@ -59,9 +59,9 @@ public class WordDocBuilderEndNotes extends WordDocBuilderSingleImageSearchCall{
public String buildWordDoc(List<HitBase> content, String title){
- String outputDocFinename = absPath+"written/"+ title.replace(' ','_').replace('\"', ' ').trim()+ ".docx";
+ String outputDocFilename = absPath+"written/"+ title.replace(' ','_').replace('\"', ' ').trim()+ ".docx";
- WordprocessingMLPackage wordMLPackage=null;
+ WordprocessingMLPackage wordMLPackage;
List<String> imageURLs = getAllImageSearchResults(title);
@@ -69,8 +69,7 @@ public class WordDocBuilderEndNotes extends WordDocBuilderSingleImageSearchCall{
BigInteger refId = BigInteger.ONE;
try {
wordMLPackage = WordprocessingMLPackage.createPackage();
-
-
+
CTEndnotes endnotes = null;
try {
EndnotesPart ep = new EndnotesPart();
@@ -148,8 +147,8 @@ public class WordDocBuilderEndNotes extends WordDocBuilderSingleImageSearchCall{
try {
- wordMLPackage.save(new File(outputDocFinename));
- System.out.println("Finished creating docx ="+outputDocFinename);
+ wordMLPackage.save(new File(outputDocFilename));
+ System.out.println("Finished creating docx ="+outputDocFilename);
} catch (Exception e) {
e.printStackTrace();
}
@@ -166,7 +165,7 @@ public class WordDocBuilderEndNotes extends WordDocBuilderSingleImageSearchCall{
e.printStackTrace();
}
- return outputDocFinename;
+ return outputDocFilename;
}
public static String processParagraphText(String title){
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderSingleImageSearchCall.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderSingleImageSearchCall.java
index 3bb6fe9..5218511 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderSingleImageSearchCall.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/WordDocBuilderSingleImageSearchCall.java
@@ -48,7 +48,7 @@ public class WordDocBuilderSingleImageSearchCall extends WordDocBuilder{
public String buildWordDoc(List<HitBase> content, String title){
- String outputDocFinename = absPath+"/written/"+ title.replace(' ','_').replace('\"', ' ').trim()+ ".docx";
+ String outputDocFilename = absPath+"/written/"+ title.replace(' ','_').replace('\"', ' ').trim()+ ".docx";
WordprocessingMLPackage wordMLPackage;
List<String> imageURLs = getAllImageSearchResults(title);
@@ -98,22 +98,22 @@ public class WordDocBuilderSingleImageSearchCall extends WordDocBuilder{
}
- wordMLPackage.save(new File(outputDocFinename));
- System.out.println("Finished creating docx ="+outputDocFinename);
+ wordMLPackage.save(new File(outputDocFilename));
+ System.out.println("Finished creating docx ="+outputDocFilename);
//TODO pdf export
/*
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
- OutputStream os = new java.io.FileOutputStream(outputDocFinename.replace(".docx", ".pdf"));
+ OutputStream os = new java.io.FileOutputStream(outputDocFilename.replace(".docx", ".pdf"));
Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
- System.out.println("Finished creating docx's PDF ="+outputDocFinename);
+ System.out.println("Finished creating docx's PDF ="+outputDocFilename);
*/
} catch (Exception e) {
e.printStackTrace();
}
- return outputDocFinename;
+ return outputDocFilename;
}
protected void addImageByImageURLToPackage(int count,
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/solrconfig.xml b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/solrconfig.xml
index 3a9db3b..9e645fc 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/solrconfig.xml
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/solr/solrconfig.xml
@@ -37,7 +37,7 @@
-->
<luceneMatchVersion>LUCENE_40</luceneMatchVersion>
- <!-- lib directives can be used to instruct Solr to load an Jars
+ <!-- lib directives can be used to instruct Solr to load Jars
identified and use them to resolve any "plugins" specified in
your solrconfig.xml or schema.xml (ie: Analyzers, Request
Handlers, etc...).
@@ -132,10 +132,10 @@
LimitTokenCountFilterFactory in your fieldType definition. E.g.
<filter class="solr.LimitTokenCountFilterFactory" maxTokenCount="10000"/>
-->
- <!-- Maximum time to wait for a write lock (ms) for an IndexWriter. Default: 1000 -->
+ <!-- Maximum time to wait for a write-lock (ms) for an IndexWriter. Default: 1000 -->
<!-- <writeLockTimeout>1000</writeLockTimeout> -->
- <!-- Expert: Enabling compound file will use less files for the index,
+ <!-- Expert: Enabling compound file will use fewer files for the index,
using fewer file descriptors on the expense of performance decrease.
Default in Lucene is "true". Default in Solr is "false" (since 3.6) -->
<!-- <useCompoundFile>false</useCompoundFile> -->
@@ -220,7 +220,7 @@
-->
<!-- Expert: Controls how often Lucene loads terms into memory
- Default is 128 and is likely good for most everyone.
+ Default is 128 and is likely good for almost everyone.
-->
<!-- <termIndexInterval>128</termIndexInterval> -->
@@ -468,7 +468,7 @@
<!-- Query Result Cache
- Caches results of searches - ordered lists of document ids
+ Caches result of searches - ordered lists of document ids
(DocList) based on a query, a sort, and the range of documents requested.
-->
<queryResultCache class="solr.LRUCache"
@@ -1365,7 +1365,7 @@
This is purely as an example.
- In reality you will likely want to add the component to your
+ In reality, you will likely want to add the component to your
already specified request handlers.
-->
<requestHandler name="/tvrh" class="solr.SearchHandler" startup="lazy">
@@ -1450,7 +1450,7 @@
This is purely as an example.
- In reality you will likely want to add the component to your
+ In reality, you will likely want to add the component to your
already specified request handlers.
-->
<requestHandler name="/clustering"
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxoQuerySnapshotMatcher.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxoQuerySnapshotMatcher.java
index 29ff0d2..f605555 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxoQuerySnapshotMatcher.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxoQuerySnapshotMatcher.java
@@ -107,14 +107,14 @@ public class TaxoQuerySnapshotMatcher {
return score;
}
- /**
+ /*
* It loads a serialized taxonomy in .dat format and serializes it into a much
* more readable XML format.
*
- * @param taxonomyPath
* @param taxonomyXML_Path
- *
-
+ * @param taxo
+ */
+ /*
public void convertDatToXML(String taxonomyXML_Path, TaxonomySerializer taxo) {
XStream xStream = new XStream();
FileHandler fileHandler = new FileHandler();
@@ -124,9 +124,10 @@ public class TaxoQuerySnapshotMatcher {
e.printStackTrace();
LOG.info(e.toString());
}
-
}
+ */
+ /*
public void xmlWork() {
TaxoQuerySnapshotMatcher matcher = new TaxoQuerySnapshotMatcher(
"src/test/resources/taxonomies/irs_domTaxo.dat");
@@ -135,7 +136,8 @@ public class TaxoQuerySnapshotMatcher {
matcher.taxo = (TaxonomySerializer) xStream.fromXML(fileHandler
.readFromTextFile("src/test/resources/taxo_English.xml"));
}
-*/
+ */
+
public void close() {
sm.close();
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyExtenderViaMebMining.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyExtenderViaMebMining.java
index 75708f8..3a77f8c 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyExtenderViaMebMining.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyExtenderViaMebMining.java
@@ -39,8 +39,6 @@ import opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcess
* commonalities of search results snapshots output map 1) for the entity,
* derived list output map 2) for such manual list of words -> derived list of
* words
- *
- *
*/
public class TaxonomyExtenderViaMebMining extends BingQueryRunner {
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomySerializer.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomySerializer.java
index 1153110..0fc1387 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomySerializer.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomySerializer.java
@@ -99,8 +99,7 @@ public class TaxonomySerializer implements Serializable {
taxo_list = new ArrayList<String[]>();
List<List<String>> entriesList = new ArrayList<List<String>>( assocWords_ExtendedAssocWords.keySet());
for(List<String> e: entriesList){
- List<String> lines = new ArrayList<String>();
- lines.addAll(e);
+ List<String> lines = new ArrayList<String>(e);
for(List<String> ls: assocWords_ExtendedAssocWords.get(e)){
lines.add(ls.toString());
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/FileHandler.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/FileHandler.java
index 9cc1952..3604234 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/FileHandler.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/FileHandler.java
@@ -135,7 +135,7 @@ public class FileHandler {
/**
* Creates a byte array from any object.
- *
+ * <p>
* I wanted to use it when I write out object to files! (This is not in use
* right now, I may move it into other class)
*
@@ -367,7 +367,7 @@ public class FileHandler {
}
/**
- * Returns the number of individual files in a directory (Not ercursive)
+ * Returns the number of individual files in a directory (Not recursive)
*
* @param dirPath
* @return
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java
index 3b012d6..aaf66f6 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/PageFetcher.java
@@ -112,7 +112,7 @@ public class PageFetcher {
reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
} catch (Exception e) {
- // we dont always need to log trial web pages if access fails
+ // we don't always need to log trial web pages if access fails
log.severe(e.toString());
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/ValueSortMap.java b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/ValueSortMap.java
index 770dde6..e3587c2 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/ValueSortMap.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/similarity/apps/utils/ValueSortMap.java
@@ -38,17 +38,17 @@ public class ValueSortMap {
}
/**
- * This method returns the new LinkedHashMap sorted with values for passed
- * Comparater. If null values exist they will be put in the last of the
+ * Returns the new {@link LinkedHashMap} sorted with values for passed
+ * {@link Comparator}. If null values exist they will be put in the last of the
* returned LinkedHashMap. If there are duplicate values they will come
- * together at the values ordering order but ordering between same multiple
- * values is ramdom. Passed Map will be intect.
+ * together at the values ordering, but ordering between same multiple
+ * values is random. Passed Map will be intect.
*
* @param inMap
* Map to be sorted
* @param comparator
- * Values will be sorted as per passed Comparater
- * @return LinkedHashMap Sorted new LinkedHashMap
+ * Values will be sorted as per passed {@link Comparator}
+ * @return A sorted new {@link LinkedHashMap} instance.
*/
public static <K, V> LinkedHashMap<K, V> sortMapByValue(Map<K, V> inMap,
Comparator<V> comparator) {
@@ -56,18 +56,18 @@ public class ValueSortMap {
}
/**
- * This method returns the new LinkedHashMap sorted with values for passed
+ * Returns the new {@link LinkedHashMap} sorted with values for passed
* ascendingOrder. If null values exist they will be put in the last for true
- * value of ascendingOrder or will be put on top of the returned LinkedHashMap
+ * value of ascendingOrder or will be put on top of the returned {@link LinkedHashMap}
* for false value of ascendingOrder. If there are duplicate values they will
- * come together at the values ordering order but ordering between same
- * multiple values is ramdom. Passed Map will be intect.
+ * come together at the values ordering but ordering between same
+ * multiple values is random. Passed Map will be intect.
*
* @param inMap
* Map to be sorted
* @param ascendingOrder
* Values will be sorted as per value of ascendingOrder
- * @return LinkedHashMap Sorted new LinkedHashMap
+ * @return A sorted new {@link LinkedHashMap} instance.
*/
public static <K, V> LinkedHashMap<K, V> sortMapByValue(Map<K, V> inMap,
boolean ascendingOrder) {
@@ -75,37 +75,37 @@ public class ValueSortMap {
}
/**
- * This method returns the new LinkedHashMap sorted with values in ascending
+ * This method returns the new {@link LinkedHashMap} sorted with values in ascending
* order. If null values exist they will be put in the last of the returned
- * LinkedHashMap. If there are duplicate values they will come together at the
- * values ordering order but ordering between same multiple values is ramdom.
+ * {@link LinkedHashMap}. If there are duplicate values they will come together at the
+ * values ordering but ordering between same multiple values is random.
* Passed Map will be intect.
*
* @param inMap
* Map to be sorted
- * @return LinkedHashMap Sorted new LinkedHashMap
+ * @return A sorted new {@link LinkedHashMap} instance.
*/
public static <K, V> LinkedHashMap<K, V> sortMapByValue(Map<K, V> inMap) {
return sortMapByValue(inMap, null, null);
}
/**
- * This method returns the new LinkedHashMap sorted with values. Values will
+ * This method returns the new {@link LinkedHashMap} sorted with values. Values will
* be sorted as value of passed comparator if ascendingOrder is null or in
* order of passed ascendingOrder if it is not null. If null values exist they
* will be put in the last for true value of ascendingOrder or will be put on
- * top of the returned LinkedHashMap for false value of ascendingOrder. If
- * there are duplicate values they will come together at the values ordering
- * order but ordering between same multiple values is ramdom. Passed Map will
+ * top of the returned {@link LinkedHashMap} for false value of ascendingOrder. If
+ * there are duplicate values they will come together at the values
+ * order but ordering between same multiple values is random. Passed Map will
* be intect.
*
* @param inMap
* Map to be sorted
* @param comparator
- * Values will be sorted as per passed Comparater
+ * Values will be sorted as per passed {@link Comparator}
* @param ascendingOrder
* Values will be sorted as per value of ascendingOrder
- * @return LinkedHashMap Sorted new LinkedHashMap
+ * @return A sorted new {@link LinkedHashMap} instance.
*/
private static <K, V> LinkedHashMap<K, V> sortMapByValue(Map<K, V> inMap,
Comparator<V> comparator, Boolean ascendingOrder) {
@@ -120,7 +120,7 @@ public class ValueSortMap {
HashSet distinctValues = new HashSet(values); // To know the distinct values
// in passed Map
- // Do handing for null values. remove them from the list that will be used
+ // Handling for null values: remove them from the list that will be used
// for sorting
int iNullValueCount = 0; // Total number of null values present in passed
// Map
@@ -165,8 +165,7 @@ public class ValueSortMap {
HashMap hmNullValueMap = new HashMap();
if (bAllDistinct) {
- // There are no multiple same values in the passed map (without consedring
- // null)
+ // There are no multiple same values of the passed map (without considering null)
keySet = inMap.keySet();
itKeyList = keySet.iterator();
while (itKeyList.hasNext()) {
@@ -200,7 +199,7 @@ public class ValueSortMap {
sortedMap.putAll(hmNullValueMap);
}
} else {
- // There are some multiple values (with out considering null)
+ // There are some multiple values (without considering null)
keySet = inMap.keySet();
itKeyList = keySet.iterator();
while (itKeyList.hasNext()) {
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/stemmer/PStemmer.java b/opennlp-similarity/src/main/java/opennlp/tools/stemmer/PStemmer.java
index 56e0965..33c7213 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/stemmer/PStemmer.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/stemmer/PStemmer.java
@@ -25,7 +25,7 @@ import org.apache.lucene.util.ArrayUtil;
/**
* Stemmer, implementing the Porter Stemming Algorithm
- *
+ * <p>
* The Stemmer class transforms a word into its root form. The input
* word can be provided a character at time (by calling add()), or at once
* by calling one of the various stem(something) methods.
@@ -44,15 +44,15 @@ public class PStemmer
}
/**
- * reset() resets the stemmer so it can stem another word. If you invoke
- * the stemmer by calling add(char) and then stem(), you must call reset()
- * before starting another word.
+ * Resets the stemmer, so it can stem another word. If you invoke
+ * the stemmer by calling {@link #add(char)} and then {@link #stem()}, you must call
+ * {@code reset()} before starting another word.
*/
public void reset() { i = 0; dirty = false; }
/**
- * Add a character to the word being stemmed. When you are finished
- * adding characters, you can call stem(void) to process the word.
+ * Add a character to the word being stemmed. When you are finished
+ * adding characters, you can call {@link #stem()} to process the word.
*/
public void add(char ch) {
if (b.length <= i) {
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeChunk.java b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeChunk.java
index 51184f2..891a26a 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeChunk.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeChunk.java
@@ -461,25 +461,25 @@ public class ParseTreeChunk implements Serializable {
public String listToString(List<List<ParseTreeChunk>> chunks) {
StringBuffer buf = new StringBuffer();
if (chunks.get(0).size() > 0) {
- buf.append(" np " + chunks.get(0).toString());
+ buf.append(" np ").append(chunks.get(0).toString());
}
if (chunks.get(1).size() > 0) {
- buf.append(" vp " + chunks.get(1).toString());
+ buf.append(" vp ").append(chunks.get(1).toString());
}
if (chunks.size() < 3) {
return buf.toString();
}
if (chunks.get(2).size() > 0) {
- buf.append(" prp " + chunks.get(2).toString());
+ buf.append(" prp ").append(chunks.get(2).toString());
}
if (chunks.get(3).size() > 0) {
- buf.append(" pp " + chunks.get(3).toString());
+ buf.append(" pp ").append(chunks.get(3).toString());
}
if (chunks.get(4).size() > 0) {
- buf.append(" adjp " + chunks.get(4).toString());
+ buf.append(" adjp ").append(chunks.get(4).toString());
}
if (chunks.get(5).size() > 0) {
- buf.append(" whadvp " + chunks.get(5).toString());
+ buf.append(" whadvp ").append(chunks.get(5).toString());
}
/*
* if (mainPos.equals("np")) np.add(ch); else if (mainPos.equals( "vp"))
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeMatcherDeterministic.java b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeMatcherDeterministic.java
index 919b636..0f2fd20 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeMatcherDeterministic.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/ParseTreeMatcherDeterministic.java
@@ -213,8 +213,7 @@ public class ParseTreeMatcherDeterministic {
*
* @param sent1
* @param sent2
- * @return List<List<ParseTreeChunk>> list of list of POS-words pairs for each
- * resultant matched / overlapped phrase
+ * @return List<List<ParseTreeChunk>> list of POS-words pairs for each resultant matched / overlapped phrase.
*/
public List<List<ParseTreeChunk>> matchTwoSentencesGroupedChunksDeterministic(
List<List<ParseTreeChunk>> sent1, List<List<ParseTreeChunk>> sent2) {
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/SentencePairMatchResult.java b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/SentencePairMatchResult.java
index 17bae04..5fe2050 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/SentencePairMatchResult.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/SentencePairMatchResult.java
@@ -24,7 +24,7 @@ import org.apache.commons.lang.StringUtils;
public class SentencePairMatchResult {
public List<List<ParseTreeChunk>> matchResult;
- private static Logger LOG = Logger
+ private static final Logger LOG = Logger
.getLogger("opennlp.tools.textsimilarity.SentencePairMatchResult");
public List<List<ParseTreeChunk>> getMatchResult() {
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/TextProcessor.java b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/TextProcessor.java
index 6dd1f2f..c490f0e 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/TextProcessor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/TextProcessor.java
@@ -31,11 +31,12 @@ import java.util.Map;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import opennlp.tools.stemmer.PStemmer;
-import opennlp.tools.similarity.apps.utils.Pair;
import org.apache.commons.lang.StringUtils;
+import opennlp.tools.stemmer.PStemmer;
+import opennlp.tools.similarity.apps.utils.Pair;
+
public class TextProcessor {
private static final Logger LOG = Logger
@@ -373,13 +374,10 @@ public class TextProcessor {
* StopList.getInstance().isStopWord(p2.trim())){ continue; }
*/
- StringBuilder buf = new StringBuilder();
- buf.append(p1);
- buf.append(" ");
- buf.append(p2);
- String b = buf.toString().toLowerCase();
+ String buf = p1 + " " + p2;
+ String b = buf.toLowerCase();
// don't add punc tokens
- if (b.indexOf("<punc>") != -1 && !retainPunc)
+ if (b.contains("<punc>") && !retainPunc)
continue;
float freq = 1;
@@ -712,7 +710,7 @@ public class TextProcessor {
if (finalSummary.trim().length() < 5) {
finalSummary = txt;
}
- // see if have a punc in the first 30 chars
+ // see if we have a punctuation character in the first 30 chars
int highestIdx = -1;
int sIdx = Math.min(finalSummary.length() - 1, 45);
for (String p : puncChars) {
@@ -785,7 +783,7 @@ public class TextProcessor {
public static String trimSentence(String txt, String title) {
- // iterate backwards looking for the first all cap word..
+ // iterate backwards looking for the first all cap word.
int numCapWords = 0;
int firstIdx = -1;
String cleaned = txt;
@@ -898,9 +896,7 @@ public class TextProcessor {
String[] tks = s.split(" ");
List<String> tokens = Arrays.asList(tks);
HashMap<String, Integer> ut = TextProcessor.getUniqueTokenIndex(tokens);
- for (String t : ut.keySet()) {
- allTokens.add(t);
- }
+ allTokens.addAll(ut.keySet());
}
HashMap<String, Integer> uniqueTokens = TextProcessor
.getUniqueTokenIndex(allTokens);
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserCacheSerializer.java b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserCacheSerializer.java
index 52cbdef..d8c6515 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserCacheSerializer.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserCacheSerializer.java
@@ -51,42 +51,36 @@ import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter;
public class ParserCacheSerializer {
- private static Logger LOG = Logger
+ private static final Logger LOG = Logger
.getLogger("opennlp.tools.textsimilarity.chunker2matcher.ParserCacheSerializer");
- private static boolean javaObjectSerialization = false;
- private static String RESOURCE_DIR = "src/test/resources/";
+ private static final boolean javaObjectSerialization = false;
+ private static final String RESOURCE_DIR = "src/test/resources/";
public static String parseCacheFileName = "sentence_parseObject.dat";
public static String parseCacheFileNameCSV = "sentence_parseObject.csv";
public static void writeObject(Object objectToSerialize) {
if (javaObjectSerialization) {
String filename = RESOURCE_DIR + parseCacheFileName;
- FileOutputStream fos = null;
- ObjectOutputStream out = null;
- try {
- fos = new FileOutputStream(filename);
- out = new ObjectOutputStream(fos);
+ try(FileOutputStream fos = new FileOutputStream(filename);
+ ObjectOutputStream out = new ObjectOutputStream(fos)) {
+
out.writeObject(objectToSerialize);
- out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
Map<String, String[][]> sentence_parseObject = (Map<String, String[][]>) objectToSerialize;
- List<String> keys = new ArrayList<String>(sentence_parseObject.keySet());
- try {
- CSVWriter writer = new CSVWriter(new FileWriter(RESOURCE_DIR
- + parseCacheFileNameCSV, false));
+ List<String> keys = new ArrayList<>(sentence_parseObject.keySet());
+ try (CSVWriter writer = new CSVWriter(
+ new FileWriter(RESOURCE_DIR + parseCacheFileNameCSV, false))) {
for (String k : keys) {
String[][] triplet = sentence_parseObject.get(k);
writer.writeNext(new String[] { k });
writer.writeNext(triplet[0]);
writer.writeNext(triplet[1]);
writer.writeNext(triplet[2]);
-
}
- writer.close();
} catch (IOException e) {
LOG.severe(e.getMessage());
}
@@ -98,13 +92,10 @@ public class ParserCacheSerializer {
if (javaObjectSerialization) {
String filename = RESOURCE_DIR + parseCacheFileName;
Object data = null;
- FileInputStream fis = null;
- ObjectInputStream in = null;
- try {
- fis = new FileInputStream(filename);
- in = new ObjectInputStream(fis);
- data = (Object) in.readObject();
- in.close();
+ try (FileInputStream fis = new FileInputStream(filename);
+ ObjectInputStream in = new ObjectInputStream(fis)) {
+
+ data = in.readObject();
} catch (IOException ex) {
System.out.println("Cant find parsing cache file ");
} catch (ClassNotFoundException ex) {
@@ -112,12 +103,10 @@ public class ParserCacheSerializer {
}
return data;
} else {
- CSVReader reader = null;
- List<String[]> lines = null;
+ List<String[]> lines;
- try {
- reader = new CSVReader(new FileReader(RESOURCE_DIR
- + parseCacheFileNameCSV), ',');
+ try (CSVReader reader = new CSVReader(new FileReader(RESOURCE_DIR
+ + parseCacheFileNameCSV), ',')) {
lines = reader.readAll();
} catch (FileNotFoundException e) {
if (javaObjectSerialization)
@@ -127,8 +116,7 @@ public class ParserCacheSerializer {
ioe.printStackTrace();
return null;
}
- Map<String, String[][]> sentence_parseObject = new HashMap<String, String[][]>();
- int count = 0;
+ Map<String, String[][]> sentence_parseObject = new HashMap<>();
for (int i = 0; i < lines.size() - 3; i += 4) {
String key = lines.get(i)[0];
String[][] value = new String[][] { lines.get(i + 1), lines.get(i + 2),
@@ -141,8 +129,4 @@ public class ParserCacheSerializer {
}
- public class ParserObjectSer {
-
- }
-
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessor.java b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessor.java
index 789642f..df070b0 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessor.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessor.java
@@ -127,8 +127,7 @@ public class ParserChunker2MatcherProcessor {
}
}
- // closing the processor, clearing loaded ling models and serializing parsing
- // cache
+ // closing the processor, clearing loaded ling models and serializing parsing cache
public void close() {
instance = null;
ParserCacheSerializer.writeObject(sentence_parseObject);
@@ -319,9 +318,7 @@ public class ParserChunker2MatcherProcessor {
}
/**
- *
- * @param para
- * input text string which is assumed to be a sentence
+ * @param sentence The input text string which is assumed to be a sentence
* @return a list of lists of phrases with their POS tags for each phrase type
* (noun, verb etc.)
*/
@@ -604,75 +601,42 @@ public class ParserChunker2MatcherProcessor {
}
protected void initializeTokenizer() {
- InputStream is = null;
- try {
- is = new FileInputStream(MODEL_DIR + "/en-token.bin");
+ try (InputStream is = new FileInputStream(MODEL_DIR + "/en-token.bin")) {
TokenizerModel model = new TokenizerModel(is);
tokenizer = new TokenizerME(model);
} catch (IOException e) {
- // we swallow exception to support the cached run
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) { // we swallow exception to support the cached run
- }
- }
+ // we swallow exception to support the cached run
}
+ // we swallow exception to support the cached run
}
protected void initializePosTagger() {
- InputStream is = null;
- try {
- is = new FileInputStream(MODEL_DIR + "/en-pos-maxent.bin");
+ try (InputStream is = new FileInputStream(MODEL_DIR + "/en-pos-maxent.bin")) {
POSModel model = new POSModel(is);
posTagger = new POSTaggerME(model);
} catch (IOException e) {
- // we swallow exception to support the cached run
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
+ // we swallow exception to support the cached run
}
}
protected void initializeParser() {
- InputStream is = null;
- try {
- is = new FileInputStream(MODEL_DIR + "/en-parser-chunking.bin");
+ try (InputStream is = new FileInputStream(MODEL_DIR + "/en-parser-chunking.bin")) {
ParserModel model = new ParserModel(is);
parser = ParserFactory.create(model);
} catch (IOException e) {
//e.printStackTrace();
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) { // we swallow exception to support the cached run
- }
- }
}
+ // we swallow exception to support the cached run
}
private void initializeChunker() {
- InputStream is = null;
- try {
- is = new FileInputStream(MODEL_DIR + "/en-chunker.bin");
+ try (InputStream is = new FileInputStream(MODEL_DIR + "/en-chunker.bin")) {
ChunkerModel model = new ChunkerModel(is);
chunker = new ChunkerME(model);
} catch (IOException e) {
//e.printStackTrace();
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) { // we swallow exception to support the cached run
- }
- }
}
+ // we swallow exception to support the cached run
}
/**
@@ -697,11 +661,11 @@ public class ParserChunker2MatcherProcessor {
if (type.equals(AbstractBottomUpParser.TOP_NODE)
&& childrenNodeList != null && childrenNodeList.size() > 0) {
PhraseNode rootNode;
- try {
- rootNode = (PhraseNode) childrenNodeList.get(0);
- } catch (Exception e) {
- return null;
- }
+ try {
+ rootNode = (PhraseNode) childrenNodeList.get(0);
+ } catch (Exception e) {
+ return null;
+ }
return new SentenceNode(text, rootNode.getChildren());
}
@@ -742,10 +706,8 @@ public class ParserChunker2MatcherProcessor {
* and does similarity assessment by finding the set of all maximum common
* subtrees of the set of parse trees for each portion of text
*
- * @param input
- * text 1
- * @param input
- * text 2
+ * @param para1 text 1
+ * @param para2 text 2
* @return the matching results structure, which includes the similarity score
*/
public SentencePairMatchResult assessRelevance(String para1, String para2) {
@@ -779,8 +741,7 @@ public class ParserChunker2MatcherProcessor {
}
public void printParseTree(String phrase1) {
- ParserChunker2MatcherProcessor p = ParserChunker2MatcherProcessor
- .getInstance();
+ ParserChunker2MatcherProcessor p = ParserChunker2MatcherProcessor.getInstance();
List<List<SentenceNode>> nodeListList = p.parseTextNode(phrase1);
for (List<SentenceNode> nodeList : nodeListList) {
for (SentenceNode node : nodeList) {
@@ -789,19 +750,3 @@ public class ParserChunker2MatcherProcessor {
}
}
}
-
-/*
- *
- * java.lang.ClassCastException: opennlp.tools.textsimilarity.chunker2matcher.WordNode cannot be cast to opennlp.tools.textsimilarity.chunker2matcher.PhraseNode
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.toSyntacticTreeNode(ParserChunker2MatcherProcessor.java:699)
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.sentenceToSentenceNode(ParserChunker2MatcherProcessor.java:525)
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.parseSentenceNode(ParserChunker2MatcherProcessor.java:554)
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.parseSentenceNode(ParserChunker2MatcherProcessor.java:548)
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.parseChunkSentence(ParserChunker2MatcherProcessor.java:282)
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.formGroupedPhrasesFromChunksForSentence(ParserChunker2MatcherProcessor.java:355)
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.formGroupedPhrasesFromChunksForPara(ParserChunker2MatcherProcessor.java:250)
- at opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor.assessRelevance(ParserChunker2MatcherProcessor.java:747)
- at opennlp.tools.similarity.apps.RelatedSentenceFinder.augmentWithMinedSentencesAndVerifyRelevance(RelatedSentenceFinder.java:458)
- at opennlp.tools.similarity.apps.RelatedSentenceFinder.generateContentAbout(RelatedSentenceFinder.java:156)
- at
- */
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserConstants.java b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserConstants.java
index 7d02210..59a8798 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserConstants.java
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/chunker2matcher/ParserConstants.java
@@ -19,73 +19,73 @@ package opennlp.tools.textsimilarity.chunker2matcher;
public interface ParserConstants {
// added new POS types for infinitive phrase and participle phrase
- public static final String TYPE_STP = "STP"; // infinitive phrase
- public static final String TYPE_SGP = "SGP"; // present participle phrase
- public static final String TYPE_SNP = "SNP"; // past participle phrase
+ String TYPE_STP = "STP"; // infinitive phrase
+ String TYPE_SGP = "SGP"; // present participle phrase
+ String TYPE_SNP = "SNP"; // past participle phrase
// below are the standard POS types,
// http://bulba.sdsu.edu/jeanette/thesis/PennTags.html
- public static final String TYPE_ADJP = "ADJP";
- public static final String TYPE_ADVP = "ADVP";
- public static final String TYPE_CC = "CC";
- public static final String TYPE_CD = "CD";
- public static final String TYPE_CONJP = "CONJP";
- public static final String TYPE_DT = "DT";
- public static final String TYPE_EX = "EX";
- public static final String TYPE_FRAG = "FRAG";
- public static final String TYPE_FW = "FW";
- public static final String TYPE_IN = "IN";
- public static final String TYPE_INTJ = "INTJ";
- public static final String TYPE_JJ = "JJ";
- public static final String TYPE_JJR = "JJR";
- public static final String TYPE_JJS = "JJS";
- public static final String TYPE_LS = "LS";
- public static final String TYPE_LST = "LST";
- public static final String TYPE_MD = "MD";
- public static final String TYPE_NAC = "NAC";
- public static final String TYPE_NN = "NN";
- public static final String TYPE_NNS = "NNS";
- public static final String TYPE_NNP = "NNP";
- public static final String TYPE_NNPS = "NNPS";
- public static final String TYPE_NP = "NP";
- public static final String TYPE_NX = "NX";
- public static final String TYPE_PDT = "PDT";
- public static final String TYPE_POS = "POS";
- public static final String TYPE_PP = "PP";
- public static final String TYPE_PRN = "PRN";
- public static final String TYPE_PRP = "PRP";
- public static final String TYPE_PRP$ = "PRP$";
- public static final String TYPE_PRT = "PRT";
- public static final String TYPE_QP = "QP";
- public static final String TYPE_RB = "RB";
- public static final String TYPE_RBR = "RBR";
- public static final String TYPE_RBS = "RBS";
- public static final String TYPE_RP = "RP";
- public static final String TYPE_RRC = "RRC";
- public static final String TYPE_S = "S";
- public static final String TYPE_SBAR = "SBAR";
- public static final String TYPE_SBARQ = "SBARQ";
- public static final String TYPE_SINV = "SINV";
- public static final String TYPE_SQ = "SQ";
- public static final String TYPE_SYM = "SYM";
- public static final String TYPE_TO = "TO";
- public static final String TYPE_TOP = "TOP";
- public static final String TYPE_UCP = "UCP";
- public static final String TYPE_UH = "UH";
- public static final String TYPE_VB = "VB";
- public static final String TYPE_VBD = "VBD";
- public static final String TYPE_VBG = "VBG";
- public static final String TYPE_VBN = "VBN";
- public static final String TYPE_VBP = "VBP";
- public static final String TYPE_VBZ = "VBZ";
- public static final String TYPE_VP = "VP";
- public static final String TYPE_WDT = "WDT";
- public static final String TYPE_WHADJP = "WHADJP";
- public static final String TYPE_WHADVP = "WHADVP";
- public static final String TYPE_WHNP = "WHNP";
- public static final String TYPE_WHPP = "WHPP";
- public static final String TYPE_WP = "WP";
- public static final String TYPE_WP$ = "WP$";
- public static final String TYPE_WRB = "WRB";
- public static final String TYPE_X = "X";
+ String TYPE_ADJP = "ADJP";
+ String TYPE_ADVP = "ADVP";
+ String TYPE_CC = "CC";
+ String TYPE_CD = "CD";
+ String TYPE_CONJP = "CONJP";
+ String TYPE_DT = "DT";
+ String TYPE_EX = "EX";
+ String TYPE_FRAG = "FRAG";
+ String TYPE_FW = "FW";
+ String TYPE_IN = "IN";
+ String TYPE_INTJ = "INTJ";
+ String TYPE_JJ = "JJ";
+ String TYPE_JJR = "JJR";
+ String TYPE_JJS = "JJS";
+ String TYPE_LS = "LS";
+ String TYPE_LST = "LST";
+ String TYPE_MD = "MD";
+ String TYPE_NAC = "NAC";
+ String TYPE_NN = "NN";
+ String TYPE_NNS = "NNS";
+ String TYPE_NNP = "NNP";
+ String TYPE_NNPS = "NNPS";
+ String TYPE_NP = "NP";
+ String TYPE_NX = "NX";
+ String TYPE_PDT = "PDT";
+ String TYPE_POS = "POS";
+ String TYPE_PP = "PP";
+ String TYPE_PRN = "PRN";
+ String TYPE_PRP = "PRP";
+ String TYPE_PRP$ = "PRP$";
+ String TYPE_PRT = "PRT";
+ String TYPE_QP = "QP";
+ String TYPE_RB = "RB";
+ String TYPE_RBR = "RBR";
+ String TYPE_RBS = "RBS";
+ String TYPE_RP = "RP";
+ String TYPE_RRC = "RRC";
+ String TYPE_S = "S";
+ String TYPE_SBAR = "SBAR";
+ String TYPE_SBARQ = "SBARQ";
+ String TYPE_SINV = "SINV";
+ String TYPE_SQ = "SQ";
+ String TYPE_SYM = "SYM";
+ String TYPE_TO = "TO";
+ String TYPE_TOP = "TOP";
+ String TYPE_UCP = "UCP";
+ String TYPE_UH = "UH";
+ String TYPE_VB = "VB";
+ String TYPE_VBD = "VBD";
+ String TYPE_VBG = "VBG";
+ String TYPE_VBN = "VBN";
+ String TYPE_VBP = "VBP";
+ String TYPE_VBZ = "VBZ";
+ String TYPE_VP = "VP";
+ String TYPE_WDT = "WDT";
+ String TYPE_WHADJP = "WHADJP";
+ String TYPE_WHADVP = "WHADVP";
+ String TYPE_WHNP = "WHNP";
+ String TYPE_WHPP = "WHPP";
+ String TYPE_WP = "WP";
+ String TYPE_WP$ = "WP$";
+ String TYPE_WRB = "WRB";
+ String TYPE_X = "X";
}
diff --git a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/readme.txt b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/readme.txt
index 483917f..b8a4f7a 100644
--- a/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/readme.txt
+++ b/opennlp-similarity/src/main/java/opennlp/tools/textsimilarity/readme.txt
@@ -15,7 +15,7 @@ parse_thicket.apps.lattice_queries
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreemnets. See the NOTICE file distributed with
+ * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
@@ -39,7 +39,7 @@ Similarity component can be used on top of search to improve relevance, computin
Also, this component is useful for web mining of images, videos, forums, blogs, and other media with textual descriptions. Such applications as content generation
and filtering meaningless speech recognition results are included in the sample applications of this component.
Relevance assessment is based on machine learning of syntactic parse trees (constituency trees, http://en.wikipedia.org/wiki/Parse_tree).
-The similarity score is calculated as the size of all maximal common sub-trees for sentences from a pair of texts (
+The similarity score is calculated as the size of all maximal common subtrees for sentences from a pair of texts (
www.aaai.org/ocs/index.php/WS/AAAIW11/paper/download/3971/4187, www.aaai.org/ocs/index.php/FLAIRS/FLAIRS11/paper/download/2573/3018,
www.aaai.org/ocs/index.php/SSS/SSS10/paper/download/1146/1448).
The objective of Similarity component is to give an application engineer as tool for text relevance which can be used as a black box, no need to understand
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorEvaluatorParams.java b/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorEvaluatorParams.java
index 22c42cf..833b5c0 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorEvaluatorParams.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorEvaluatorParams.java
@@ -25,7 +25,7 @@ import opennlp.tools.cmdline.params.EncodingParameter;
/**
* Common evaluation parameters.
- *
+ * <p>
* Note: Do not use this class, internal use only!
*/
public interface DisambiguatorEvaluatorParams extends EncodingParameter,
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorToolParams.java b/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorToolParams.java
index 1e64e51..97fd8d9 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorToolParams.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/cmdline/disambiguator/DisambiguatorToolParams.java
@@ -26,7 +26,7 @@ import opennlp.tools.cmdline.params.LanguageParams;
/**
* Parameters for DisambiguatorTool.
- *
+ * <p>
* Note: Do not use this class, internal use only!
*/
interface DisambiguatorToolParams extends LanguageParams,EncodingParameter {
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/FeaturesExtractor.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/FeaturesExtractor.java
index dd50415..c28b17d 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/FeaturesExtractor.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/FeaturesExtractor.java
@@ -28,10 +28,11 @@ import java.util.HashMap;
* Disambiguation approaches.<br>
* Each set of methods refer to one approach
* <ul>
- * <li>IMS (It Makes Sense): check {@link https
- * ://www.comp.nus.edu.sg/~nght/pubs/ims.pdf} for details about this approach</li>
- * <li>SST (SuperSense Tagging): check {@link http
- * ://ttic.uchicago.edu/~altun/pubs/CiaAlt_EMNLP06.pdf} for details about this
+ * <li>IMS (It Makes Sense): check <a href="https://www.comp.nus.edu.sg/~nght/pubs/ims.pdf">
+ * https://www.comp.nus.edu.sg/~nght/pubs/ims.pdf</a>
+ * for details about this approach</li>
+ * <li>SST (SuperSense Tagging): check <a href="https://ttic.uchicago.edu/~altun/pubs/CiaAlt_EMNLP06.pdf">
+ * https://ttic.uchicago.edu/~altun/pubs/CiaAlt_EMNLP06.pdf</a> for details about this
* approach</li>
* </ul>
*
@@ -39,8 +40,9 @@ import java.util.HashMap;
* families of features are to be extracted: - PoS of Surrounding Words: it
* requires one parameter: "Window size" - Surrounding Words: no parameters are
* required - Local Collocations: it requires one parameter: "the n-gram"
- *
- * check {@link https://www.comp.nus.edu.sg/~nght/pubs/ims.pdf} for details
+ * <p>
+ * check <a href="https://www.comp.nus.edu.sg/~nght/pubs/ims.pdf">
+ * https://www.comp.nus.edu.sg/~nght/pubs/ims.pdf</a> for details
* about this approach
*/
public class FeaturesExtractor {
@@ -75,7 +77,7 @@ public class FeaturesExtractor {
private String[] extractSurroundingWords(WTDIMS wordToDisambiguate) {
- ArrayList<String> contextWords = new ArrayList<String>();
+ ArrayList<String> contextWords = new ArrayList<>();
for (int i = 0; i < wordToDisambiguate.getSentence().length; i++) {
if (wordToDisambiguate.getLemmas() != null) {
@@ -97,12 +99,12 @@ public class FeaturesExtractor {
}
private String[] extractLocalCollocations(WTDIMS wordToDisambiguate, int ngram) {
- /**
+ /*
* Here the author used only 11 features of this type. the range was set to
* 3 (bigrams extracted in a way that they are at max separated by 1 word).
*/
- ArrayList<String> localCollocations = new ArrayList<String>();
+ ArrayList<String> localCollocations = new ArrayList<>();
for (int i = wordToDisambiguate.getWordIndex() - ngram; i <= wordToDisambiguate
.getWordIndex() + ngram; i++) {
@@ -133,7 +135,7 @@ public class FeaturesExtractor {
}
/**
- * This methods generates the full list of Surrounding words, from the
+ * Generates the full list of Surrounding words, from the
* training data. These data will be later used for the generation of the
* features qualified of "Surrounding words
*
@@ -144,7 +146,7 @@ public class FeaturesExtractor {
public ArrayList<String> extractTrainingSurroundingWords(
ArrayList<WTDIMS> trainingData) {
- HashMap<String, Object> words = new HashMap<String, Object>();
+ HashMap<String, Object> words = new HashMap<>();
for (WTDIMS word : trainingData) {
for (String sWord : word.getSurroundingWords()) {
@@ -154,22 +156,16 @@ public class FeaturesExtractor {
}
}
- ArrayList<String> list = new ArrayList<String>();
-
- for (String word : words.keySet()) {
- list.add(word);
- }
-
- return list;
+ return new ArrayList<>(words.keySet());
}
/**
* This method generates the different set of features related to the IMS
- * approach and store them in the corresponding attributes of the WTDIMS
+ * approach and store them in the corresponding attributes of the {@link WTDIMS}
*
* @param wordToDisambiguate
- * the word to disambiguate [object: WTDIMS]
+ * the word to disambiguate [object: {@link WTDIMS}]
* @param windowSize
* the parameter required to generate the features qualified of
* "PoS of Surrounding Words"
@@ -191,19 +187,18 @@ public class FeaturesExtractor {
/**
* This generates the context of IMS. It supposes that the features have
- * already been extracted and stored in the WTDIMS object, therefore it
+ * already been extracted and stored in the {@link WTDIMS} object, therefore it
* doesn't require any parameters.
*
* @param word
* the word to disambiguate
* @param listSurrWords
* the full list of surrounding words of the training data
- * @return the Context of the wordToDisambiguate
*/
public void serializeIMSFeatures(WTDIMS word, ArrayList<String> listSurrWords) {
String[] posOfSurroundingWords = word.getPosOfSurroundingWords();
- ArrayList<String> surroundingWords = new ArrayList<String>(
+ ArrayList<String> surroundingWords = new ArrayList<>(
Arrays.asList((word.getSurroundingWords())));
String[] localCollocations = word.getLocalCollocations();
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/Lesk.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/Lesk.java
index 4ddfb13..0dba41b 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/Lesk.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/Lesk.java
@@ -64,11 +64,11 @@ public class Lesk extends WSDisambiguator {
/**
* If the parameters are null set the default ones, else only set them if they
- * valid. Invalid parameters will return a exception
+ * valid.
*
* @param params
* parameters
- * @throws InvalidParameterException
+ * @throws InvalidParameterException Thrown if specified parameters are invalid.
*/
@Override
public void setParams(WSDParameters params) throws InvalidParameterException {
@@ -197,7 +197,7 @@ public class Lesk extends WSDisambiguator {
*
* @param sample
* the word sample to disambiguate
- * @return the array of WordSenses with their scores
+ * @return the list of WordSenses with their scores
*/
public ArrayList<WordSense> extended(WSDSample sample) {
params.setWin_b_size(0);
@@ -213,7 +213,7 @@ public class Lesk extends WSDisambiguator {
*
* @param sample
* the word sample to disambiguate
- * @return the array of WordSenses with their scores
+ * @return the list of WordSenses with their scores
*/
public ArrayList<WordSense> extendedContextual(WSDSample sample) {
ArrayList<WordSense> scoredSenses;
@@ -306,7 +306,7 @@ public class Lesk extends WSDisambiguator {
*
* @param sample
* the word sample to disambiguate
- * @return the array of WordSenses with their scores
+ * @return the list of WordSenses with their scores
*/
public ArrayList<WordSense> extendedExponentialContextual(WSDSample sample) {
ArrayList<WordSense> scoredSenses;
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/OSCCWSDContextGenerator.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/OSCCWSDContextGenerator.java
index af040cf..2b3cabc 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/OSCCWSDContextGenerator.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/OSCCWSDContextGenerator.java
@@ -79,10 +79,9 @@ public class OSCCWSDContextGenerator implements WSDContextGenerator {
public String[] getContext(int index, String[] toks, String[] tags,
String[] lemmas, int ngram, int windowSize, List<String> model) {
- Set<String> surroundingContextClusters = new HashSet<>();
- surroundingContextClusters.addAll(Arrays.asList(
- extractSurroundingContext(index, toks, tags, lemmas,
- windowSize)));
+ Set<String> surroundingContextClusters = new HashSet<>(Arrays.asList(
+ extractSurroundingContext(index, toks, tags, lemmas,
+ windowSize)));
String[] serializedFeatures = new String[model.size()];
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDEvaluator.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDEvaluator.java
index cdc76cd..13d1e67 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDEvaluator.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDEvaluator.java
@@ -27,16 +27,15 @@ import opennlp.tools.util.eval.Mean;
*
* @see Evaluator
* @see WSDisambiguator
- * @see WordToDisambiguate
*/
public class WSDEvaluator extends Evaluator<WSDSample> {
- private Mean accuracy = new Mean();
+ private final Mean accuracy = new Mean();
/**
* The {@link WSDisambiguator} used to create the disambiguated senses.
*/
- private WSDisambiguator disambiguator;
+ private final WSDisambiguator disambiguator;
/**
* Initializes the current instance with the given {@link WSDisambiguator}.
@@ -52,7 +51,7 @@ public class WSDEvaluator extends Evaluator<WSDSample> {
this.disambiguator = disambiguator;
}
- // @Override
+ @Override
protected WSDSample processSample(WSDSample reference) {
String[] referenceSenses = reference.getSenseIDs();
@@ -82,7 +81,7 @@ public class WSDEvaluator extends Evaluator<WSDSample> {
/**
* Retrieves the WSD accuracy.
- *
+ * <p>
* This is defined as: WSD accuracy = correctly disambiguated / total words
*
* @return the WSD accuracy
@@ -101,7 +100,7 @@ public class WSDEvaluator extends Evaluator<WSDSample> {
}
/**
- * Represents this objects as human readable {@link String}.
+ * Represents this objects as human-readable {@link String}.
*/
@Override
public String toString() {
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDParameters.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDParameters.java
index 4b5b329..05fd420 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDParameters.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDParameters.java
@@ -32,7 +32,7 @@ public abstract class WSDParameters {
protected SenseSource senseSource;
/**
- * @return if the disambiguation type is coarse grained or fine grained
+ * @return if the disambiguation type is coarse grained or fine-grained
*/
public SenseSource getSenseSource() {
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSample.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSample.java
index 16b4b8f..d7a4cd2 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSample.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSample.java
@@ -129,7 +129,7 @@ public class WSDSample {
public String toString() {
StringBuilder result = new StringBuilder();
- result.append("target at : " + this.targetPosition + " in : ");
+ result.append("target at : ").append(this.targetPosition).append(" in : ");
for (int i = 0; i < getSentence().length; i++) {
result.append(i);
result.append(".");
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSampleStream.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSampleStream.java
index d85cf4f..ad17dc7 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSampleStream.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDSampleStream.java
@@ -18,7 +18,6 @@
package opennlp.tools.disambiguator;
import java.io.IOException;
-import java.io.Reader;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -28,7 +27,7 @@ import opennlp.tools.util.ObjectStream;
public class WSDSampleStream extends FilterObjectStream<String, WSDSample> {
- private static Logger logger = Logger.getLogger(WSDSampleStream.class.getName());
+ private static final Logger logger = Logger.getLogger(WSDSampleStream.class.getName());
/**
* Initializes the current instance.
@@ -44,8 +43,8 @@ public class WSDSampleStream extends FilterObjectStream<String, WSDSample> {
/**
* Parses the next sentence and return the next {@link WSDSample} object.
- *
- * If an error occurs an empty {@link WSDSample} object is returned and an
+ * <p>
+ * If an error occurs an empty {@link WSDSample} object is returned and a
* warning message is logged. Usually it does not matter if one of many
* sentences is ignored.
*/
@@ -66,7 +65,7 @@ public class WSDSampleStream extends FilterObjectStream<String, WSDSample> {
.warning("Error during parsing, ignoring sentence: " + sentence);
}
- sample = null;// new WSDSample(new String[]{}, new String[]{},0);
+ sample = null; // new WSDSample(new String[]{}, new String[]{},0);
}
return sample;
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguator.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguator.java
index f7d516a..eea72bd 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguator.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguator.java
@@ -30,13 +30,13 @@ import opennlp.tools.util.Span;
* different senses of the ambiguous word. Disambiguation can be achieved in
* either supervised or un-supervised approaches. A disambiguator returns a
* sense ID.
- *
+ * <p>
* <b>How it works :<b> Just supply the context as an array of tokens and the
* index of the target word to the disambiguate method.
- *
- * Otherwise for multiple words, you can set a word span instead of simply one
+ * <p>
+ * Otherwise, for multiple words, you can set a word span instead of simply one
* index. For the moment the source of sense definitions is from WordNet. *
- *
+ * <p>
* Examples on how to use each approach are provided in the test section.
*
*/
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguatorME.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguatorME.java
index 01d4bb3..979f4a5 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguatorME.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WSDisambiguatorME.java
@@ -28,6 +28,7 @@ import opennlp.tools.util.TrainingParameters;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -107,9 +108,7 @@ public class WSDisambiguatorME extends WSDisambiguator {
sample.getSentence(), sample.getLemmas(), windowSize);
if (words.length > 0) {
- for (String word : words) {
- surroundingWordsModel.add(word);
- }
+ surroundingWordsModel.addAll(Arrays.asList(words));
}
}
samples.reset();
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WTDIMS.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WTDIMS.java
index 64a2d41..53d81fb 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WTDIMS.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/WTDIMS.java
@@ -19,12 +19,7 @@
package opennlp.tools.disambiguator;
-import java.util.ArrayList;
-import java.util.List;
-
import net.sf.extjwnl.data.POS;
-import opennlp.tools.disambiguator.WSDHelper;
-import opennlp.tools.disambiguator.WSDSample;
public class WTDIMS {
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Paragraph.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Paragraph.java
index 2610ea8..2a14cec 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Paragraph.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Paragraph.java
@@ -28,13 +28,13 @@ public class Paragraph {
public Paragraph() {
super();
- this.isentences = new ArrayList<Sentence>();
+ this.isentences = new ArrayList<>();
}
public Paragraph(int pnum) {
super();
this.pnum = pnum;
- this.isentences = new ArrayList<Sentence>();
+ this.isentences = new ArrayList<>();
}
public Paragraph(int pnum, ArrayList<Sentence> sentences) {
@@ -74,12 +74,11 @@ public class Paragraph {
}
/**
- * This return TRUE only and only if the paragraph contains the word and it is
+ * Returns {@code true} only and only if the paragraph contains the word, and it is
* sense-tagged
*
* @param wordTag
- * @return {@value Boolean.true} if the word exists in the paragraph and is
- * sense-tagged
+ * @return {@code true} if the word exists in the paragraph and is sense-tagged.
*
*/
public boolean contains(String wordTag) {
diff --git a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Word.java b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Word.java
index 47dd16a..3210b41 100644
--- a/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Word.java
+++ b/opennlp-wsd/src/main/java/opennlp/tools/disambiguator/datareader/Word.java
@@ -71,7 +71,7 @@ public class Word {
* @param wnum
* id of the word in the sentence
* @param type
- * the type in this case is {@link Type.DWORD}
+ * the type in this case is {@link Type#WORD}
* @param word
* The raw word, as it appears in the sentence
* @param cmd
@@ -112,7 +112,7 @@ public class Word {
* @param snum
* id of the sentence
* @param type
- * the type in this case is {@link Type.DWORD}
+ * the type in this case is {@link Type#WORD}
* @param word
* The raw word, as it appears in the sentence
* @param cmd
diff --git a/summarizer/src/main/java/opennlp/summarization/Sentence.java b/summarizer/src/main/java/opennlp/summarization/Sentence.java
index c80026a..c4f2c9f 100755
--- a/summarizer/src/main/java/opennlp/summarization/Sentence.java
+++ b/summarizer/src/main/java/opennlp/summarization/Sentence.java
@@ -29,7 +29,7 @@ import opennlp.summarization.preprocess.StopWords;
* A representation of a sentence geared toward pagerank and summarization.
*/
public class Sentence {
- //sentId is always position of sentence in doc..
+ //sentId is always position of sentence in doc.
private int sentId;
private String stringVal;
private Score pageRankScore;
@@ -132,7 +132,7 @@ public class Sentence {
return wordCnt==0? this.getStringVal().split(" ").length: wordCnt;
}
- //Should add an article id to the sentence class.. For now returns true if the ids are the same..
+ //Should add an article id to the sentence class. For now returns true if the ids are the same.
@Override
public boolean equals(Object o){
if(! (o instanceof Sentence)) return false;
diff --git a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractor.java b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractor.java
index acf6390..6ec073e 100644
--- a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractor.java
+++ b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractor.java
@@ -27,10 +27,10 @@ import java.util.List;
public class LexChainingKeywordExtractor {
// Simple logic to pull out the keyword based on longest lexical chains..
- public List<String> getKeywords(List<LexicalChain> lexicalChains, int noOfKeywrds){
+ public List<String> getKeywords(List<LexicalChain> lexicalChains, int noOfKeywords){
Collections.sort(lexicalChains);
List<String> ret = new ArrayList<>();
- for(int i = 0; i < Math.min(lexicalChains.size(), noOfKeywrds); i++) {
+ for(int i = 0; i < Math.min(lexicalChains.size(), noOfKeywords); i++) {
List<Word> words = lexicalChains.get(i).getWord();
if(words.size()>0 &&!ret.contains(words.get(0).getLexicon())){
ret.add(words.get(0).getLexicon());
diff --git a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexicalChainingSummarizer.java b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexicalChainingSummarizer.java
index c95a07a..c1fdcab 100755
--- a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexicalChainingSummarizer.java
+++ b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/LexicalChainingSummarizer.java
@@ -98,7 +98,7 @@ public class LexicalChainingSummarizer implements Summarizer{
//chaincnt++
// End loop LC
}
- //Could not add the word to any existing list.. Start a new lexical chain with the word..
+ //Could not add the word to any existing list. Start a new lexical chain with the word.
if(chainsAddCnt==0) {
List<Word> senses = wordRel.getWordSenses(noun);
for(Word w : senses) {
@@ -117,16 +117,16 @@ public class LexicalChainingSummarizer implements Summarizer{
// disambiguateAndCleanChains(lc, chains);
// Calculate score
// Length of chain * homogeneity
- //sort LC by strength..
+ //sort LC by strength.
return lc;
}
/*
- * A way to manage the number of lexical chains generated. Expire very small lexical chains ..
+ * A way to manage the number of lexical chains generated. Expire very small lexical chains.
* Takes care to only remove small chains that were added "long back"
*/
private void purge(List<LexicalChain> lc, int sentId, int totSents) {
- //Do nothing for the first 50 sentences..
+ //Do nothing for the first 50 sentences.
if(lc.size()<20 ) return;
Collections.sort(lc);
@@ -141,7 +141,7 @@ public class LexicalChainingSummarizer implements Summarizer{
LexicalChain l = lc.get(i);
if(l.score() < cutOff && (sentId - l.last) > totSents/3)// && containsAllWords(words, l.word))
toRem.add(l);
- //A different sense and added long back..
+ //A different sense and added long back.
else if(words.containsKey(l.getWord().get(0).getLexicon()) && (sentId - l.start) > totSents/10)
toRem.add(l);
else
diff --git a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/Word.java b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/Word.java
index e6a191a..08fb6a2 100644
--- a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/Word.java
+++ b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/Word.java
@@ -19,15 +19,13 @@ package opennlp.summarization.lexicalchaining;
public interface Word {
- //Lexicon..
String getLexicon();
void setLexicon(String lex);
- //Sense of a word..
+ // Sense of a word.
Object getSense();
void setSense(Object senseID);
- //ID for a word..
Object getID();
void setID(Object id);
}
\ No newline at end of file
diff --git a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelation.java b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelation.java
index c2bfb75..175c173 100644
--- a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelation.java
+++ b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelation.java
@@ -19,7 +19,7 @@ package opennlp.summarization.lexicalchaining;
public class WordRelation {
- //Match strength constants for lexical chains..
+ //Match strength constants for lexical chains.
public static int STRONG_RELATION = 0;
public static int MED_RELATION = 1;
public static int WEAK_RELATION = 2;
diff --git a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelationshipDetermination.java b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelationshipDetermination.java
index 4485ecb..fca0d07 100644
--- a/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelationshipDetermination.java
+++ b/summarizer/src/main/java/opennlp/summarization/lexicalchaining/WordRelationshipDetermination.java
@@ -62,10 +62,11 @@ public class WordRelationshipDetermination {
private IWord isSynonym(String noun, Word w) {
WordnetWord ww = (WordnetWord)w;
- IWord ret = null;
+ IWord ret;
IIndexWord idxNoun = dictionary.getIndexWord(noun, POS.NOUN);
- /*getWordIDs() returns all the WordID associated with a index
+ /*
+ * getWordIDs() returns all the WordID associated with an index
*
*/
// for(IWordID wordID : idxWord.getWordIDs())
@@ -89,7 +90,7 @@ public class WordRelationshipDetermination {
return ret;
}
/*
- * Returns true if the word represented by idxNoun is present in a synset..
+ * Returns true if the word represented by idxNoun is present in a synset.
*/
private IWord inSynset(ISynset wordSynset, IIndexWord idxNoun)
{
@@ -172,9 +173,9 @@ public class WordRelationshipDetermination {
*/
public WordRelation getRelation(LexicalChain l, String noun, boolean checkMed) {
WordRelation ret = new WordRelation();
- ret.relation = ret.NO_RELATION;
+ ret.relation = WordRelation.NO_RELATION;
for(Word w : l.word) {
- //Exact match is a string relation..
+ //Exact match is a string relation.
if(w.getLexicon().equalsIgnoreCase(noun)) {
ret.relation = WordRelation.STRONG_RELATION;
ret.src = w;
diff --git a/summarizer/src/main/java/opennlp/summarization/meta/MetaSummarizer.java b/summarizer/src/main/java/opennlp/summarization/meta/MetaSummarizer.java
index 1defeb2..6b23dd9 100644
--- a/summarizer/src/main/java/opennlp/summarization/meta/MetaSummarizer.java
+++ b/summarizer/src/main/java/opennlp/summarization/meta/MetaSummarizer.java
@@ -35,7 +35,7 @@ import opennlp.summarization.textrank.TextRankSummarizer;
import opennlp.summarization.DocProcessor;
/*
* A summarizer that combines results from the text rank algorithm and the lexical chaining algorithm.
- * It runs both algorithm and uses the the lexical chains to identify the main topics and relative importance
+ * It runs both algorithm and uses the lexical chains to identify the main topics and relative importance
* and the text rank to pick sentences from lexical chains.
*/
public class MetaSummarizer {
@@ -57,8 +57,8 @@ public class MetaSummarizer {
return s;
}
- // Rank sentences by merging the scores from lexical chaining and text rank..
- // maxWords -1 indicates rank all sentences..
+ // Rank sentences by merging the scores from lexical chaining and text rank.
+ // maxWords -1 indicates rank all sentences.
public int getBestSent(LexicalChain l, Hashtable<Integer, Score> pageRankScores) {
double bestScore = 0; int bestStr=-1;
for(Sentence s : l.getSentences())
diff --git a/summarizer/src/main/java/opennlp/summarization/preprocess/DefaultDocProcessor.java b/summarizer/src/main/java/opennlp/summarization/preprocess/DefaultDocProcessor.java
index 818b71e..a56ace5 100755
--- a/summarizer/src/main/java/opennlp/summarization/preprocess/DefaultDocProcessor.java
+++ b/summarizer/src/main/java/opennlp/summarization/preprocess/DefaultDocProcessor.java
@@ -78,7 +78,7 @@ public class DefaultDocProcessor implements DocProcessor {
{
String sentence = str.substring(start,end);//str.substring(oldSentEndIdx, sentEndIdx).trim();
- //Add the sentence as-is; do any processing at the word level..
+ //Add the sentence as-is; do any processing at the word level
//To lower case and trim all punctuations
sentences.add(sentence);
wrdItr.setText(sentence);
@@ -91,12 +91,12 @@ public class DefaultDocProcessor implements DocProcessor {
String word = sentence.substring(wrdStrt, wrdEnd);//words[i].trim();
word = word.replaceAll("\"|'","");
- //Skip stop words and stem the word..
+ //Skip stop words and stem the word
if(sw.isStopWord(word)) continue;
String stemedWrd = stemmer.stem(word).toString();
- //update iidx by adding the current sentence to the list..
+ //update iidx by adding the current sentence to the list
if(iidx!=null)
{
if(stemedWrd.length()>1)
@@ -182,7 +182,7 @@ public class DefaultDocProcessor implements DocProcessor {
List<String> sentStrs = new ArrayList<>();
List<String> cleanedSents = new ArrayList<>();
- //Custom/simple method if specified or open nlp model was not found..
+ //Custom/simple method if specified or open nlp model was not found
if(sentModel==null || SENTENCE_FRAG==SIMPLE)
getSentences(text, sentStrs, null, cleanedSents);
else{
diff --git a/summarizer/src/main/java/opennlp/summarization/preprocess/PorterStemmer.java b/summarizer/src/main/java/opennlp/summarization/preprocess/PorterStemmer.java
index 27a1a5c..85878cb 100755
--- a/summarizer/src/main/java/opennlp/summarization/preprocess/PorterStemmer.java
+++ b/summarizer/src/main/java/opennlp/summarization/preprocess/PorterStemmer.java
@@ -55,7 +55,7 @@ import opennlp.tools.stemmer.Stemmer;
/**
* Stemmer, implementing the Porter Stemming Algorithm
- *
+ * <p>
* The Stemmer class transforms a word into its root form. The input
* word can be provided a character at time (by calling add()), or at once
* by calling one of the various stem(something) methods.
diff --git a/summarizer/src/main/java/opennlp/summarization/textrank/TextRank.java b/summarizer/src/main/java/opennlp/summarization/textrank/TextRank.java
index 3fb6b24..7e2a6b7 100755
--- a/summarizer/src/main/java/opennlp/summarization/textrank/TextRank.java
+++ b/summarizer/src/main/java/opennlp/summarization/textrank/TextRank.java
@@ -49,19 +49,20 @@ public class TextRank {
private DocProcessor docProc;
private final double title_wt = 0;
- private Hashtable<Integer, String[]> wordsInSent;
+
+ // private Hashtable<Integer, String[]> wordsInSent;
// DAMPING FACTOR..
- private static double df = 0.15;
+ private static final double df = 0.15;
private static final boolean HIGHER_TITLE_WEIGHT = true;
private static final double TITLE_WRD_WT = 2d;
- private final String resources = "./resources";
public TextRank(DocProcessor dp) {
sw = new StopWords();
setLinks(new Hashtable<>());
processedSent = new ArrayList<>();
docProc = dp;
+ String resources = "./resources";
wordWt = IDFWordWeight.getInstance(resources + "/idf.csv");
}
@@ -164,8 +165,8 @@ public class TextRank {
return currWtScores;
}
- // Raw score is sigma wtsimilarity of neighbors..
- // Used in the denominator of the Text rank formula..
+ // Raw score is sigma wtsimilarity of neighbors.
+ // Used in the denominator of the Text rank formula.
public List<Score> getNeighborsSigmaWtSim(List<String> sentences,
Hashtable<String, List<Integer>> iidx, Hashtable<String, Double> wts) {
List<Score> allScores = new ArrayList<>();
diff --git a/tagging-server/src/main/resources/htmls/annotation-editor.js b/tagging-server/src/main/resources/htmls/annotation-editor.js
index 6a811a9..f97a2bf 100644
--- a/tagging-server/src/main/resources/htmls/annotation-editor.js
+++ b/tagging-server/src/main/resources/htmls/annotation-editor.js
@@ -69,7 +69,7 @@ AnnotationEditor.prototype.removeAnnotation = function(annotationId) {
// Selection handling and navigation depends highly
// on the annotation task. There is no default way of
// doing it which fits all tasks.
-// Therefore we should implement a few default tools which
+// Therefore, we should implement a few default tools which
// can be registered if required.
// Registers a previous and forward key shortcuts to navigate based on span types.
@@ -84,7 +84,7 @@ AnnotationEditor.prototype.setNavigationByFunctionKeys = function(previousKey, n
// If a user clicks with a mouse on something he expects a reaction
-// It should be possible to register a function which helps dealing with
+// It should be possible to register a function which helps to deal with
// such a selection in a default way
// e.g. user wants to select a few tokens
diff --git a/tagging-server/src/main/resources/htmls/opennlp-demo.js b/tagging-server/src/main/resources/htmls/opennlp-demo.js
index 545b9a6..6de5822 100644
--- a/tagging-server/src/main/resources/htmls/opennlp-demo.js
+++ b/tagging-server/src/main/resources/htmls/opennlp-demo.js
@@ -59,7 +59,7 @@
$("div#opennlp-demo-result").empty();
- // Extract tokens and names from the array array
+ // Extract tokens and names from the array
var tokens = [];
var annotations = [];
diff --git a/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/AnnotatingMarkupParser.java b/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/AnnotatingMarkupParser.java
index 13969e2..cb39418 100644
--- a/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/AnnotatingMarkupParser.java
+++ b/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/AnnotatingMarkupParser.java
@@ -168,7 +168,7 @@ public class AnnotatingMarkupParser implements ITextConverter {
hasSpecialHandling = true;
} else if (oAttributes != null
&& oAttributes.get(WIKIOBJECT_ATTR_KEY) instanceof ImageFormat) {
- // the caption of images often holds well formed
+ // the caption of images often holds well-formed
// sentences with links to entities
hasSpecialHandling = true;
ImageFormat iformat = (ImageFormat) oAttributes.get(WIKIOBJECT_ATTR_KEY);
diff --git a/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/UimaUtil.java b/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/UimaUtil.java
index 745ec11..3039e10 100644
--- a/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/UimaUtil.java
+++ b/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/UimaUtil.java
@@ -55,18 +55,18 @@ public class UimaUtil {
XMLParser xmlParser = UIMAFramework.getXMLParser();
- TypeSystemDescription typeSystemDesciptor;
+ TypeSystemDescription typeSystemDescriptor;
try {
- typeSystemDesciptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
+ typeSystemDescriptor = (TypeSystemDescription) xmlParser.parse(xmlTypeSystemSource);
- typeSystemDesciptor.resolveImports();
+ typeSystemDescriptor.resolveImports();
} catch (InvalidXMLException e) {
e.printStackTrace();
- typeSystemDesciptor = null;
+ typeSystemDescriptor = null;
}
- return typeSystemDesciptor;
+ return typeSystemDescriptor;
}
static CAS createEmptyCAS(TypeSystemDescription typeSystem) {