Skip to content

Commit

Permalink
Include opentasks-provider as a module into Opentasks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfs committed Mar 29, 2017
1 parent 4d1ee1f commit 83faf64
Show file tree
Hide file tree
Showing 61 changed files with 11,397 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.3.0'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 31 14:01:03 CEST 2016
#Sat Mar 18 00:03:31 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
1 change: 1 addition & 0 deletions opentasks-provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions opentasks-provider/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 8
targetSdkVersion 25
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('org.dmfs:rfc5545-datetime:0.2.4')
compile('org.dmfs:lib-recur:0.9.6')
testCompile 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions opentasks-provider/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/marten/.local/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
13 changes: 13 additions & 0 deletions opentasks-provider/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="org.dmfs.tasks.provider"
>

<application android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>

</application>

</manifest>
198 changes: 198 additions & 0 deletions opentasks-provider/src/main/java/org/dmfs/ngrams/NGramGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
* Copyright (C) 2014 Marten Gajda <marten@dmfs.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dmfs.ngrams;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;


/**
* Generator for N-grams from a given String.
*
* @author Marten Gajda <marten@dmfs.org>
*/
public final class NGramGenerator
{
/**
* A {@link Pattern} that matches anything that doesn't belong to a word or number.
*/
private final static Pattern SEPARATOR_PATTERN = Pattern.compile("[^\\p{L}\\p{M}\\d]+");

/**
* A {@link Pattern} that matches anything that doesn't belong to a word.
*/
private final static Pattern SEPARATOR_PATTERN_NO_NUMBERS = Pattern.compile("[^\\p{L}\\p{M}]+");

private final int mN;
private final int mMinWordLen;
private boolean mAllLowercase = true;
private boolean mReturnNumbers = true;
private boolean mAddSpaceInFront = false;
private Locale mLocale = Locale.getDefault();

private char[] mTempArray;


public NGramGenerator(int n)
{
this(n, 1);
}


public NGramGenerator(int n, int minWordLen)
{
mN = n;
mMinWordLen = minWordLen;
mTempArray = new char[n];
mTempArray[0] = ' ';
}


/**
* Set whether to convert all words to lower-case first.
*
* @param lowercase
* true to convert the test to lower case first.
* @return This instance.
*/
public NGramGenerator setAllLowercase(boolean lowercase)
{
mAllLowercase = lowercase;
return this;
}


/**
* Set whether to index the beginning of a word with a space in front. This slightly raises the weight of word beginnings when searching.
*
* @param addSpace
* <code>true</code> to add a space in front of each word, <code>false</code> otherwise.
* @return This instance.
*/
public NGramGenerator setAddSpaceInFront(boolean addSpace)
{
mAddSpaceInFront = addSpace;
return this;
}


/**
* Sets the {@link Locale} to use when converting the input string to lower case. This has no effect when {@link #setAllLowercase(boolean)} is called with
* <code>false</code>.
*
* @param locale
* The {@link Locale} to user for the conversion to lower case.
* @return This instance.
*/
public NGramGenerator setLocale(Locale locale)
{
mLocale = locale;
return this;
}


/**
* Get all N-grams contained in the given String.
*
* @param data
* The String to analyze.
* @return A {@link Set} containing all N-grams.
*/
public Set<String> getNgrams(String data)
{
Set<String> result = new HashSet<String>(128);

return getNgrams(result, data);
}


/**
* Get all N-grams contained in the given String.
*
* @param set
* The set to add all the N-grams to, or <code>null</code> to create a new set.
* @param data
* The String to analyze.
*
* @return The {@link Set} containing the N-grams.
*/
public Set<String> getNgrams(Set<String> set, String data)
{
if (mAllLowercase)
{
data = data.toLowerCase(mLocale);
}

String[] words = mReturnNumbers ? SEPARATOR_PATTERN.split(data) : SEPARATOR_PATTERN_NO_NUMBERS.split(data);

if (set == null)
{
set = new HashSet<String>(128);
}

for (String word : words)
{
getNgrams(word, set);
}

return set;
}


public void getNgrams(String word, Set<String> ngrams)
{
final int len = word.length();
final int minWordLen = mMinWordLen;

if (len < minWordLen)
{
return;
}

final int n = mN;
final int last = Math.max(1, len - n + 1);

for (int i = 0; i < last; ++i)
{
ngrams.add(word.substring(i, Math.min(i + n, len)));
}

if (mAddSpaceInFront)
{
/*
* Add another String with a space and the first n-1 characters of the word.
*
* We could just call
*
* ngrams.add(" " + word.substring(0, Math.min(len, n - 1));
*
* But it's probably way more efficient like this:
*/
char[] tempArray = mTempArray;

int count = Math.min(len, n - 1);
for (int i = 0; i < count; ++i)
{
tempArray[i + 1] = word.charAt(i);
}
ngrams.add(new String(tempArray));
}
}
}
Loading

0 comments on commit 83faf64

Please sign in to comment.