Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
stumped by a Scala error message
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Geoffrey S. Knauth  
View profile  
 More options Apr 23 2012, 8:46 am
From: "Geoffrey S. Knauth" <ge...@knauth.org>
Date: Mon, 23 Apr 2012 08:46:23 -0400
Local: Mon, Apr 23 2012 8:46 am
Subject: stumped by a Scala error message
I have a line of Scala code that looks like this:

    val sentences : List[CoreMap] = document.get(classOf[SentencesAnnotation])

document is an edu.stanford.nlp.pipeline.Annotation

The original Java code from Stanford [1] looked like this:

    List<CoreMap> sentences = document.get(SentencesAnnotation.class);

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.

Is what I'm doing wrong obvious to anyone?

Geoff

[1] http://nlp.stanford.edu/software/corenlp.shtml


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Edmondo Porcu  
View profile  
 More options Apr 23 2012, 8:56 am
From: Edmondo Porcu <edmondo.po...@gmail.com>
Date: Mon, 23 Apr 2012 14:56:11 +0200
Local: Mon, Apr 23 2012 8:56 am
Subject: Re: [scala-user] stumped by a Scala error message
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

val sentences:List[ValueType,KeyType] = ....

Best Regards
Edmondo

2012/4/23 Geoffrey S. Knauth <ge...@knauth.org>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Compall  
View profile  
 More options Apr 23 2012, 9:06 am
From: Stephen Compall <stephen.comp...@gmail.com>
Date: Mon, 23 Apr 2012 09:06:34 -0400
Local: Mon, Apr 23 2012 9:06 am
Subject: Re: [scala-user] stumped by a Scala error message

On Apr 23, 2012 8:46 AM, "Geoffrey S. Knauth" <ge...@knauth.org> wrote:

>    val sentences : List[CoreMap] =

document.get(classOf[SentencesAnnotation])

>    List<CoreMap> sentences = document.get(SentencesAnnotation.class);

>    public <VALUE,KEY extends TypesafeMap.Key<CoreMap,VALUE>> VALUE

get(Class<KEY> key)

> Is what I'm doing wrong obvious to anyone?

List means scala.collections.immutable.List in the Scala code.

Try what Edmondo said about leaving off the type of your val; it should be
able to infer the right type here.

--
Stephen Compall
Greetings from sunny Appleton!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoffrey S. Knauth  
View profile  
 More options Apr 23 2012, 9:12 am
From: "Geoffrey S. Knauth" <ge...@knauth.org>
Date: Mon, 23 Apr 2012 09:12:37 -0400
Local: Mon, Apr 23 2012 9:12 am
Subject: Re: [scala-user] stumped by a Scala error message
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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Edmondo Porcu  
View profile  
 More options Apr 23 2012, 10:08 am
From: Edmondo Porcu <edmondo.po...@gmail.com>
Date: Mon, 23 Apr 2012 16:08:47 +0200
Local: Mon, Apr 23 2012 10:08 am
Subject: Re: [scala-user] stumped by a Scala error message
There is a reason for that, and the reason is that the type inferer in
Scala is way more powerful and sophisticated then in Java.

If the type inferer can't guess it, in most of the cases this is the
sign of a problem in the API.

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?

Best Regards
Edmondo

2012/4/23 Geoffrey S. Knauth <ge...@knauth.org>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoffrey S. Knauth  
View profile  
 More options Apr 23 2012, 3:48 pm
From: "Geoffrey S. Knauth" <ge...@knauth.org>
Date: Mon, 23 Apr 2012 15:48:56 -0400
Local: Mon, Apr 23 2012 3:48 pm
Subject: Re: [scala-user] stumped by a Scala error message
On Apr 23, 2012, at 10:08 , Edmondo Porcu wrote:

> 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) ?

----------------------------------------------------------------------
JavaDoc for:
  edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation

All Implemented Interfaces:
  CoreAnnotation<List<CoreMap>>, TypesafeMap.Key<CoreMap,List<CoreMap>>
Enclosing class:
  CoreAnnotations


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Compall  
View profile  
 More options Apr 23 2012, 6:32 pm
From: Stephen Compall <stephen.comp...@gmail.com>
Date: Mon, 23 Apr 2012 18:32:32 -0400
Local: Mon, Apr 23 2012 6:32 pm
Subject: Re: [scala-user] stumped by a Scala error message

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoffrey S. Knauth  
View profile  
 More options Apr 24 2012, 10:08 am
From: "Geoffrey S. Knauth" <ge...@knauth.org>
Date: Tue, 24 Apr 2012 10:08:18 -0400
Local: Tues, Apr 24 2012 10:08 am
Subject: Re: [scala-user] stumped by a Scala error message
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.

import java.util.Properties
import edu.stanford.nlp.pipeline.StanfordCoreNLP
import edu.stanford.nlp.pipeline.Annotation
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation

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])
  }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoffrey S. Knauth  
View profile  
 More options Apr 24 2012, 10:54 am
From: "Geoffrey S. Knauth" <ge...@knauth.org>
Date: Tue, 24 Apr 2012 10:54:17 -0400
Local: Tues, Apr 24 2012 10:54 am
Subject: Re: [scala-user] stumped by a Scala error message
Edmondo:  YOU FIXED IT !!  Thanks!  I owe you dinner sometime.

For everyone else, this was the fix:

< document.get(classOf[SentencesAnnotation])
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoffrey S. Knauth  
View profile  
 More options Apr 25 2012, 9:53 am
From: "Geoffrey S. Knauth" <ge...@knauth.org>
Date: Wed, 25 Apr 2012 09:53:27 -0400
Local: Wed, Apr 25 2012 9:53 am
Subject: Re: [scala-user] stumped by a Scala error message
For the mail archive user's reference, while researching a related problem, I ran across this:

http://www.scala-lang.org/node/11972

(with regard to someone else's experience using Scala with StanfordNLP's Java code)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Schmitz  
View profile  
 More options Apr 25 2012, 12:59 pm
From: Michael Schmitz <mich...@schmitztech.com>
Date: Wed, 25 Apr 2012 09:59:45 -0700
Local: Wed, Apr 25 2012 12:59 pm
Subject: Re: [scala-user] stumped by a Scala error message

Yeah, I was going to point you to that earlier post.  Stanford CoreNLP does
some WEIRD stuff.  I really don't understand how this works in Java...

On Wed, Apr 25, 2012 at 6:53 AM, Geoffrey S. Knauth <ge...@knauth.org>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »