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

Downgrade to Guava 14.0.1 to match Spark dependency #93

Open
wants to merge 1 commit 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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.source>1.7</compiler.source>
<compiler.target>1.7</compiler.target>
<compiler.source>1.8</compiler.source>
<compiler.target>1.8</compiler.target>
</properties>

<developers>
Expand Down Expand Up @@ -228,7 +228,7 @@
<dependency><!-- used for the Optional and other things -->
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/optimaize/langdetect/i18n/LdLocale.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
package com.optimaize.langdetect.i18n;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
Expand Down Expand Up @@ -90,7 +94,7 @@ public static LdLocale fromString(@NotNull String string) {
Optional<String> script = null;
Optional<String> region = null;

List<String> strings = Splitter.on('-').splitToList(string);
List<String> strings = splitToList('-', string);
for (int i=0; i<strings.size(); i++) {
String chunk = strings.get(i);
if (i==0) {
Expand All @@ -111,6 +115,16 @@ public static LdLocale fromString(@NotNull String string) {
return new LdLocale(language, script, region);
}

private static List<String> splitToList(char separator, String string) {
Preconditions.checkNotNull(string);
Iterable<String> iterator = Splitter.on(separator).split(string);
ArrayList<String> result = new ArrayList<String>();
for (String s: iterator) {
result.add(s);
}
return Collections.unmodifiableList(result);
}

private static boolean looksLikeScriptCode(String string) {
return string.length() == 4 && string.matches("[A-Z][a-z]{3}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void extractGrams_8() {
public void stressTestAlgo2() {
NgramExtractor ngramExtractor = NgramExtractor.gramLengths(1, 2, 3);
String text = "Foo bar hello world and so on nana nunu dada dudu asdf asdf akewf köjvnawer aisdfj awejfr iajdsöfj ewi adjsköfjwei ajsdökfj ief asd";
Stopwatch stopwatch = Stopwatch.createStarted();
Stopwatch stopwatch = (new Stopwatch()).start();
for (int i=0; i<100000; i++) {
ngramExtractor.extractGrams(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testExtractNGrams2() {
@Test
public void stressTestAlgo1() {
String text = "Foo bar hello world and so on nana nunu dada dudu asdf asdf akewf köjvnawer aisdfj awejfr iajdsöfj ewi adjsköfjwei ajsdökfj ief asd";
Stopwatch stopwatch = Stopwatch.createStarted();
Stopwatch stopwatch = (new Stopwatch()).start();
for (int i=0; i<100000; i++) {
OldNgramExtractor.extractNGrams(text, null); //2.745s
}
Expand Down