Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing problems with Wikipedia dump template #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ public static void extractContextualToken(String path_to_dump, String tmp_folder
String line = br.readLine();
while (line != null) {
String[] split = Util.fastSplit(line);
redirections.put(split[0], split[1]);
//old: redirections.put(split[0], split[1]), sometimes length was 0
if(split.length > 1)
redirections.put(split[0], split[1]);
line = br.readLine();
}
br.close();
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/diffbot/wikistatsextractor/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** some Utils methods */
public class Util {
Expand Down Expand Up @@ -44,10 +46,21 @@ public static List<String> getCleanTextFromPage(String page, boolean ignore_list
}

/** go to the index of the text */
int index_text = page.indexOf("<text xml:space=\"preserve\">");
String patternStr = "<text.*xml:space=\"preserve\">";
Pattern patternIndex = Pattern.compile(patternStr);
Matcher matcherIndex = patternIndex.matcher(page);
//old pattern version: int index_text = page.indexOf("<text xml:space=\"preserve\">");
int index_text = -1;
String preserve = "";
if(matcherIndex.find()) {
index_text = matcherIndex.start();
preserve = page.substring(index_text,matcherIndex.end());
//System.out.println(preserve + "...");
}
if (index_text == -1)
return null;
index_text += "<text xml:space=\"preserve\">".length();
//index_text += "<text xml:space=\"preserve\">".length();
index_text += preserve.length();

/** locate the end */
int end_text = page.indexOf("</text>");
Expand Down