Skip to content

Commit

Permalink
#164 - Introduce checkstyle
Browse files Browse the repository at this point in the history
- Fix remaining checkstyle issues
- Use try-with-resources in some places
- Add re-generate hashcode/equals where only equals was implemented without hashcode
  • Loading branch information
reckart committed Oct 31, 2023
1 parent 1b9a679 commit d047e17
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,4 @@ private boolean fillBuffer()
} // fillBuffer

}
}
}
18 changes: 9 additions & 9 deletions dkpro-jwpl-api/src/main/java/org/dkpro/jwpl/api/Wikipedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,15 @@ public String getWikipediaId()
return sb.toString();
}

}

class ValueComparator
implements Comparator<Entry<Integer, Double>>
{

@Override
public int compare(Entry<Integer, Double> e1, Entry<Integer, Double> e2)
private static class ValueComparator
implements Comparator<Entry<Integer, Double>>
{
return Double.compare(e2.getValue(), e1.getValue());

@Override
public int compare(Entry<Integer, Double> e1, Entry<Integer, Double> e2)
{
return Double.compare(e2.getValue(), e1.getValue());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ public void processTextRow(TextParser textParser) throws IOException

int page_id = textIdPageIdMap.get(text_id);
String page_idValueP = pPageIdNameMap.get(page_id);
if (page_idValueP != null) {// pages
if (page_idValueP != null) { // pages
page.addRow(page_id, page_id, page_idValueP, textParser.getOldText(),
formatBoolean(disambiguations.contains(page_id)));
pageMapLine.addRow(page_id, page_idValueP, page_id, SQL_NULL, SQL_NULL);

}
else {
String page_idValueR = rPageIdNameMap.get(page_id);
if (page_idValueR != null) {// Redirects
if (page_idValueR != null) { // Redirects
String destination = Redirects.getRedirectDestination(textParser.getOldText());
if (destination != null) {
KeyType destinationHash = (KeyType) hashAlgorithm.hashCode(destination);
Expand All @@ -252,20 +252,18 @@ public void processTextRow(TextParser textParser) throws IOException
}
}
}

}

@Override
public void writeMetaData() throws IOException
{
TxtFileWriter outputFile = new TxtFileWriter(versionFiles.getOutputMetadata());
// ID,LANGUAGE,DISAMBIGUATION_CATEGORY,MAIN_CATEGORY,nrOfPages,nrOfRedirects,nrOfDisambiguationPages,nrOfCategories
outputFile.addRow(metaData.getId(), metaData.getLanguage(),
metaData.getDisambiguationCategory(), metaData.getMainCategory(),
metaData.getNrOfPages(), metaData.getNrOfRedirects(),
metaData.getNrOfDisambiguations(), metaData.getNrOfCategories());
outputFile.flush();
outputFile.close();
try (var outputFile = new TxtFileWriter(versionFiles.getOutputMetadata())) {
// ID, LANGUAGE, DISAMBIGUATION_CATEGORY, MAIN_CATEGORY, nrOfPages, nrOfRedirects,
// nrOfDisambiguationPages, nrOfCategories
outputFile.addRow(metaData.getId(), metaData.getLanguage(),
metaData.getDisambiguationCategory(), metaData.getMainCategory(),
metaData.getNrOfPages(), metaData.getNrOfRedirects(),
metaData.getNrOfDisambiguations(), metaData.getNrOfCategories());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ public void processPageRow(PageParser pageParser) throws IOException
// handle categories
if (page_namespace == 14) {
if (skipCategory) {
if (pageParser.getPageIsRedirect())
if (pageParser.getPageIsRedirect()) {
// skip categories that are redirects
return;
}
}
// retrieve page id and page title
page_id = pageParser.getPageId();
Expand Down Expand Up @@ -358,25 +359,26 @@ public void processTextRow(TextParser textParser) throws IOException
int page_id;

text_id = textParser.getOldId();
if (!textIdPageIdMap.containsKey(text_id))
if (!textIdPageIdMap.containsKey(text_id)) {
return;
}
page_id = textIdPageIdMap.get(text_id);
if (pPageIdNameMap.containsKey(page_id)) {// pages
if (pPageIdNameMap.containsKey(page_id)) { // pages
page.addRow(page_id, page_id, pPageIdNameMap.get(page_id), textParser.getOldText(),
formatBoolean(disambiguations.contains(page_id)));
pageMapLine.addRow(page_id, pPageIdNameMap.get(page_id), page_id, "NULL", "NULL");
return;
}
if (rPageIdNameMap.containsKey(page_id)) {// Redirects
if (rPageIdNameMap.containsKey(page_id)) { // Redirects
destination = Redirects.getRedirectDestination(textParser.getOldText());
if (!pNamePageIdMap.containsKey(destination))
if (!pNamePageIdMap.containsKey(destination)) {
return;
}
pageRedirects.addRow(pNamePageIdMap.get(destination), rPageIdNameMap.get(page_id));
pageMapLine.addRow(page_id, rPageIdNameMap.get(page_id),
pNamePageIdMap.get(destination), "NULL", "NULL");
nrOfRedirects++;
}

}

@Override
Expand Down Expand Up @@ -406,7 +408,8 @@ public void writeMetaData() throws IOException
{
try (TxtFileWriter metaData = new TxtFileWriter(
outputDir + File.separator + "MetaData.txt")) {
// ID,LANGUAGE,DISAMBIGUATION_CATEGORY,MAIN_CATEGORY,nrOfPages,nrOfRedirects,nrOfDisambiguationPages,nrOfCategories
// ID, LANGUAGE, DISAMBIGUATION_CATEGORY, MAIN_CATEGORY, nrOfPages, nrOfRedirects,
// nrOfDisambiguationPages, nrOfCategories
metaData.addRow("null", language, disambiguationsCategory, mainCategory, nrOfPages,
nrOfRedirects, nrOfDisambiguations, nrOfCategories);
metaData.export();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ public static synchronized void register(Path filePath)
}
paths.add(filePath);
}
}
}
Loading

0 comments on commit d047e17

Please sign in to comment.