Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gangeli committed May 14, 2012
1 parent 5dcdc3f commit 34c82e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/org/goobs/stanford/JavaNLP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import edu.stanford.nlp.ling.CoreAnnotations.AnswerAnnotation
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation
import edu.stanford.nlp.util.logging.Redwood
import edu.stanford.nlp.util.Function
import collection.generic.CanBuildFrom


Expand Down Expand Up @@ -160,7 +161,11 @@ object JavaNLP {




implicit def fn2Function[A,B](fn:A=>_<:B):Function[A,B] = {
new Function[A,B](){
override def apply(a:A):B = fn(a).asInstanceOf[B]
}
}

def threadAndMap[A,B,That](in:Iterable[A], fn:A=>B, numThreads:Int=Runtime.getRuntime.availableProcessors(), name:String="Threaded Map")(implicit bf:CanBuildFrom[Seq[A],B,That]):That = {
//--Variables
Expand Down
25 changes: 24 additions & 1 deletion src/org/goobs/util/Range.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.goobs.util;

import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Range implements Decodable {
public class Range implements Decodable, Iterable<Integer> {

/*
Vars
Expand Down Expand Up @@ -139,4 +141,25 @@ public int hashCode(){
public String toString(){
return encode();
}

@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>(){
private int value = startInclusive;
@Override
public boolean hasNext() {
return value < stopExclusive;
}
@Override
public Integer next() {
if(!hasNext()){ throw new NoSuchElementException(); }
value += 1;
return value-1;
}
@Override
public void remove() {
throw new RuntimeException("You're trying to do nonsense. Stop it.");
}
};
}
}

0 comments on commit 34c82e4

Please sign in to comment.