Two other Java imports of note: import edu.stanford.nlp.util.CoreMap import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation
The Scala error message I get is:
inferred type arguments [Nothing,edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation] do not conform to method get's type parameter bounds [VALUE,KEY <: edu.stanford.nlp.util.TypesafeMap.Key[edu.stanford.nlp.util.CoreMap,VALUE]]
The Javadoc for the get method says:
public <VALUE,KEY extends TypesafeMap.Key<CoreMap,VALUE>> VALUE get(Class<KEY> key) Returns the value associated with the given key or null if none is provided.
Dear Geoffrey, it looks to me that your problem is that document.get does not have 1 generic parameter, but two : Value and KEY.
The easiest way to verify what is your problem is to let the type inferer find the correct type for sentences: val sentences= document.get(classOf[SentencesAnnotation])
If the type inferer cannot guess them, you'll have to specify them, but again they will be two
> Two other Java imports of note: > import edu.stanford.nlp.util.CoreMap > import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation
> The Scala error message I get is:
> inferred type arguments [Nothing,edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation] do not conform to method get's type parameter bounds [VALUE,KEY <: edu.stanford.nlp.util.TypesafeMap.Key[edu.stanford.nlp.util.CoreMap,VALUE]]
> The Javadoc for the get method says:
> public <VALUE,KEY extends TypesafeMap.Key<CoreMap,VALUE>> VALUE get(Class<KEY> key) > Returns the value associated with the given key or null if none is provided.
On Apr 23, 2012, at 09:06 , Stephen Compall wrote:
> Try what Edmondo said about leaving off the type of your val; it should be able to infer the right type here.
Thanks for your responses. I did leave off the type and got the same error. In fact that's what I had to begin with; I just added the type to make the first email clearer. What puzzles me is how this could have worked in Java.
> On Apr 23, 2012, at 09:06 , Stephen Compall wrote:
>> Try what Edmondo said about leaving off the type of your val; it should be able to infer the right type here.
> Thanks for your responses. I did leave off the type and got the same error. In fact that's what I had to begin with; I just added the type to make the first email clearer. What puzzles me is how this could have worked in Java.
> In fact, if we look together to : > public <VALUE,KEY extends TypesafeMap.Key<CoreMap,VALUE>> VALUE > get(Class<KEY> key) > and we try to assign to a variable its result, what type its result should be?
The return type makes my brain hurt. But I don't think the Scala compiler is complaining about the return type. I think it's complaining about the argument to get(). In all the Java code I see, the argument to get() is something like SentencesAnnotation.class. One argument, a class. But when I do that in Scala, I get an error message that makes my brain hurt again. The message seems related to get's return type so at least it's the same headache.
Below, document isa edu.stanford.nlp.pipeline.Annotation.
var sentences = document.get(classOf[SentencesAnnotation])
has been giving me this error:
inferred type arguments [Nothing,edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation] do not conform to method get's type parameter bounds [VALUE,KEY <: edu.stanford.nlp.util.TypesafeMap.Key[edu.stanford.nlp.util.CoreMap,VALUE]]
Out of curiosity, I changed get's argument to: 42
var sentences = document.get(42)
type mismatch; found : Int(42) required: java.lang.Class[?]
which makes me wonder why classOf[SentencesAnnotation] was not good enough, as it was in the original Java code (SentencesAnnotation.class) ?
On Mon, 2012-04-23 at 15:48 -0400, Geoffrey S. Knauth wrote: > The return type makes my brain hurt. But I don't think the Scala > compiler is complaining about the return type.
"What has changed?" analysis begs to differ; the annotated var type in your original Scala sample is not the same as that in your Java sample.
Stephen writes: > List means scala.collections.immutable.List in the Scala code.
or maybe scala.collection..., either way.
and the supertype of SentencesAnnotation:
> TypesafeMap.Key<CoreMap,List<CoreMap>>
-- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better
On Apr 23, 2012, at 18:32 , Stephen Compall wrote:
> "What has changed?" analysis begs to differ; the annotated var type in > your original Scala sample is not the same as that in your Java sample.
I removed the annotated var type from the original Scala sample. This is the minimal set of code lines that represents my problem. The last line does not compile. Ensime highlights `document.get': it doesn't like the argument I gave, but Java was happy with SentencesAnnotation.class. If I could figure out how to make the last line compile, all my current problems would be solved.
object Tiny { def minimal() = { // see: http://nlp.stanford.edu/software/corenlp.shtml val props = new Properties props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref") val pipeline = new StanfordCoreNLP(props) val document = new Annotation("The rain in Spain falls mainly in the plain.") pipeline.annotate(document) val sentences = document.get(classOf[SentencesAnnotation]) }