# CoreNLP - Base Name Conflict

**URL:** <https://discourse.julialang.org/t/corenlp-base-name-conflict/4714>\
**Category:** General Usage\
**Tags:** nlp\
**Created:** [July 7, 2017, 11:46am UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714 "2017-07-07T11:46:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 7, 2017, 11:46am UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/1 "2017-07-07T11:46:16Z")

</div>

Hi,  
Trying to use the CoreNLP.jl package at the Julia 0.6.0 command line on Ubuntu 16.04. I’m following the instructions shown [here](https://github.com/JuliaText/CoreNLP.jl). The session looks like this–

> julia\> using CoreNLP  
> WARNING: deprecated syntax “\_ as an rvalue”.  
> julia\> corenlp\_init(“/home/john/CoreNLP/stanford-corenlp-full-2014-01-04”)  
> PyObject '\<'corenlp.corenlp.StanfordCoreNLP instance at 0x7f00038dd710\>  
> julia\> my\_parse = parse(“John ate a baked, green apple.”)  
> WARNING: both CoreNLP and Base export “parse”; uses of it in module Main must be qualified  
> ERROR: UndefVarError: parse not defined

I tried to qualify parse in two ways–

> julia\> my\_parse = CoreNLP::parse(“John ate a baked, green apple.”)  
> ERROR: UndefVarError: parse not defined

> julia\> my\_parse = CoreNLP.parse(“John ate a baked, green apple.”)  
> ERROR: UndefVarError: int not defined  
> Stacktrace:  
> [1] extract\_index at /home/john/.julia/v0.6/CoreNLP/src/CoreNLP.jl:131 [inlined]  
> [2] parse\_raw(::Dict{String,Any}, ::Symbol) at /home/john/.julia/v0.6/CoreNLP/src/CoreNLP.jl:166  
> [3] parse(::String) at /home/john/.julia/v0.6/CoreNLP/src/CoreNLP.jl:219

Apparently both the Base and CoreNLP modules create ‘parse’ and they conflict. The discussion [here](https://groups.google.com/forum/#!topic/julia-users/fT1LUf2rg_s) says to use the :: notation but, as shown above, this did not work. The discussion [here](https://github.com/JuliaLang/julia/issues/12183) seems sort of relevant but not actually useful to me.

I’d appreciate any help in getting CoreNLP working in Julia, viz., in solving this problem of the name conflict of parse() in CoreNLP vs. Julia/Base. Thanks!

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [July 7, 2017, 11:48am UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/2 "2017-07-07T11:48:42Z")

</div>

CoreNLP.jl has not been updated for three years, so I assume it does not support Julia versions more recent than 0.3. If you really want to use it, you’ll have to port it to Julia 0.6, which will likely require quite some work (though it should be doable).

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 7, 2017, 12:02pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/3 "2017-07-07T12:02:40Z")

</div>

> [@aether](#):
>
> The discussion here says to use the :: notation

And in the following post the author admitted that it’s C++ syntax, not Julia’s or Python’s. The syntax:

```julia
CoreNLP.parse("bla bla bla")

```

is correct. Your call fails because CoreNLP.jl uses type name `int` which has been deprecated a while ago.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 7, 2017, 12:24pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/4 "2017-07-07T12:24:00Z")

</div>

I tried to quickly fix it, but there’s so many issues (outdated syntax, no tests, required Python packages not installed automatically) that I’d just rewrite it altogether, removing Python as a dependency (CoreNLP itself is a Java library). It’s quite easy actually and shouldn’t take more than a couple of days. If you are brave enough to start your Julia life with creating a new package, I will help you to get started.

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 7, 2017, 4:16pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/5 "2017-07-07T16:16:07Z")

</div>

Thanks for the replies. I’m brave enough to try but will need all the help you can give. Available Sunday or Monday and I will post again then. Thanks!

---

<div class="post-metadata">

**Author:** ![malmaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/malmaud/32/29_2.png) [@malmaud](https://discourse.julialang.org/u/malmaud)\
**Post date:** [July 7, 2017, 4:51pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/6 "2017-07-07T16:51:34Z")

</div>

At the time I wrote it, there was no reliable way to call directly into the Java library. Would love to know if that’s changed in the intervening years.

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [July 7, 2017, 4:52pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/7 "2017-07-07T16:52:37Z")

</div>

> [@malmaud](#):
>
> Would love to know if that’s changed in the intervening years.

> **[GitHub - JuliaInterop/JavaCall.jl: Call Java from Julia](https://github.com/JuliaInterop/JavaCall.jl)**
>
> Call Java from Julia. Contribute to JuliaInterop/JavaCall.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 7, 2017, 9:04pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/8 "2017-07-07T21:04:27Z")

</div>

I made a starter kit for you:

[https://github.com/dfdx/JavaCoreNLP.jl](https://github.com/dfdx/JavaCoreNLP.jl)

Using it you can translate first code snippet from [CoreNLP docs](https://stanfordnlp.github.io/CoreNLP/api.html) as follows:

```julia
Pkg.clone("https://github.com/dfdx/JavaCoreNLP.jl")
Pkg.build("JavaCoreNLP") # to download and assemble Java dependencies, requires Maven

using JavaCoreNLP

pipeline = StanfordCoreNLP(Dict("annotations" =>
                    "tokenize, ssplit, pos, lemma, ner, parse, dcoref"))
doc = Annotation("The Beatles were an English rock band formed in Liverpool in 1960.")
annotate!(pipeline, doc)

```

What’s included:

- maven project that downloads CoreNLP and English model JARs and assembles them into a single “uberjar”; see [pom.xml](https://github.com/dfdx/JavaCoreNLP.jl/blob/master/jvm/corenlp-wrapper/pom.xml) if you want to add more models or customize build in any way
- [initialization script](https://github.com/dfdx/JavaCoreNLP.jl/blob/master/src/init.jl) that loads JVM with assembled dependencies whenever you call `using JavaCoreNLP`
- a few wrappers for Java classes and examples of calling their methods
- a very short [intro into JavaCall](https://github.com/dfdx/JavaCoreNLP.jl/blob/master/src/core.jl#L24-L51) so you could start writing code quickly

Feel free to clone / rename / refactor or ask any questions on the topic.

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 10, 2017, 8:34am UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/9 "2017-07-10T08:34:23Z")

</div>

THANKS. I followed the above and could make it work with some warnings from both the REPL and from Atom (Julia 0.6). The warnings were:

WARNING: deprecated syntax “inner constructor JavaObject(…) around /home/john/.julia/v0.6/JavaCall/src/core.jl:30”.  
Use “JavaObject{T}(…) where T” instead.

WARNING: deprecated syntax “inner constructor JavaObject(…) around /home/john/.julia/v0.6/JavaCall/src/core.jl:35”.  
Use “JavaObject{T}(…) where T” instead.

Loaded /usr/lib/jvm/default-java/jre/lib/amd64/server/libjvm.so

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.  
SLF4J: Defaulting to no-operation (NOP) logger implementation  
SLF4J: See [SLF4J Error Codes](http://www.slf4j.org/codes.html#StaticLoggerBinder) for further details.

Ignoring those for now, my bigger problem is, how to access the result in ‘doc’?

For comparison, from bash, I can use curl to post a query to Stanford’s online parser and send the response to an output file, e.g.,

curl --data query=‘John ate a baked green apple.’ [http://nlp.stanford.edu:8080/parser/index.jsp](http://nlp.stanford.edu:8080/parser/index.jsp) \> output.xml

The result is some xml which can be parsed to extract the desired info. Presumably, this same info exists within ‘doc’ but how do I get it?

(Usual disclaimers that I’m really dumb and ought to know this myself.)

Thanks.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 10, 2017, 9:38am UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/10 "2017-07-10T09:38:07Z")

</div>

> [@aether](#):
>
> WARNING: deprecated syntax “inner constructor JavaObject(…) around /home/john/.julia/v0.6/JavaCall/src/core.jl:30”.  
> Use “JavaObject{T}(…) where T” instead.
> 
> WARNING: deprecated syntax “inner constructor JavaObject(…) around /home/john/.julia/v0.6/JavaCall/src/core.jl:35”.  
> Use “JavaObject{T}(…) where T” instead.

These come from JavaCall which still has some deprecated syntax. You can indeed ignore it.

> [@aether](#):
>
> SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.  
> SLF4J: Defaulting to no-operation (NOP) logger implementation  
> SLF4J: See [SLF4J Error Codes](http://www.slf4j.org/codes.html#StaticLoggerBinder) for further details.

These lines tell that logger isn’t properly configured on Java side. Adding appropriate logger implementation to `pom.xml` should fix it, but normally ignore it for years 😃

> [@aether](#):
>
> curl --data query=‘John ate a baked green apple.’ [http://nlp.stanford.edu:8080/parser/index.jsp](http://nlp.stanford.edu:8080/parser/index.jsp) \> output.xml

This demo URL shows the usage of a dependency parser - one specific feature included in CoreNLP. I believe in Java API it’s represented as a `Tree` class (or maybe `SemanticGraph`, I’d check both). Here’s seems to be the [relevant section](https://stanfordnlp.github.io/CoreNLP/api.html#interpreting-the-output) in the Getting Started guide:

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

for(CoreMap sentence: sentences) {
  ...

  // this is the parse tree of the current sentence
  Tree tree = sentence.get(TreeAnnotation.class);

  // this is the Stanford dependency graph of the current sentence
  SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
}

```

So basically you need to call Java methods (using `jcall`) to iterate over the list of the sentences and extract parsed objects. Hope this is enough to get you started and feel free to follow up with any questions.

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 10, 2017, 1:45pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/11 "2017-07-10T13:45:31Z")

</div>

Hi again. In–

```julia
function Annotation(text::AbstractString)
    jann = JAnnotation((JString,), text)
    return Annotation(jann)
end

```

and also in–

```julia
function StanfordCoreNLP(props::Dict{String, String})
    jprops = to_jprops(props)
    jpipeline = JStanfordCoreNLP((JProperties,), jprops)
    return StanfordCoreNLP(jpipeline)
end

```

it looks like the returns are calling the functions themselves. Either this is a simple return and I’ve misunderstood Julia’s syntax, or it’s a recursion and I’ve misunderstood the function. Could you let me know, pls?

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [July 10, 2017, 1:56pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/12 "2017-07-10T13:56:51Z")

</div>

Julia’s functions work using the types of their arguments. To take the `Annotations` example, the code you have posted is a function that is called when its argument is some kind of a string. In that function, the `jann` variable is created, which holds an object of type `JAnnotation`. Then, when you call `Annotation(jann)` in the last line of the function, it dispatches to definition of the `Annotation` function that takes a single argument of type `JAnnotation`.

Now this function is generated automatically by the compiler. If you see the definition of the type `Annotation` in [https://github.com/dfdx/JavaCoreNLP.jl/blob/master/src/pipeline.jl#L4](https://github.com/dfdx/JavaCoreNLP.jl/blob/master/src/pipeline.jl#L4) , you will notice that it is a composite struct containing one member (or field) of type `JAnnotation`. The compiler then will automatically create a function with name `Annotation` that takes a `JAnnotation` object as a parameter. This function will then create the `Annotation` object in its body. This function is usually called the _default constructor_, but you can think of this simply as a function that creates the object.

Hope that helps. See here for more: [https://docs.julialang.org/en/stable/manual/types/#Composite-Types-1](https://docs.julialang.org/en/stable/manual/types/#Composite-Types-1)

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 12, 2017, 9:46am UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/13 "2017-07-12T09:46:52Z")

</div>

Hi. Struggling with this, maybe b/c no Java experience. I understand how to construct the pipeline and call the annotator. In order to interrogate the result, I understand I need to–

1. Import CoreMap into Julia. I tried–  
`JCoreMap = @jimport edu.stanford.nlp.util.CoreMap`  
and it worked error-free in Julia.

2. Act on doc::Annotation using [CoreMap](https://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/util/CoreMap.html)’s “[get](https://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/util/TypesafeMap.html#get-java.lang.Class-)” method to obtain a List called, e.g., sentences. I tried to build a jcall like this–  
`jcall(JCoreMap, "get", RETURN TYPE?, (Annotation,), doc::Annotation)`  
but didn’t succeed. I tried various return types but always got MethodErrors such as–

```julia
jcall(JCoreMap, "get", JCoreMap, (Annotation,), doc)
ERROR: MethodError: no method matching write(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Void)
Closest candidates are:
  write(::IO, ::Any) at io.jl:284
  write(::IO, ::Any...) at io.jl:286
  write(::IO, ::Complex) at complex.jl:175
  ...
Stacktrace:
 [1] write(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Void) at ./io.jl:284
 [2] method_signature(::Type{T} where T, ::Type{T} where T, ::Vararg{Type{T} where T,N} where N) at /home/john/.julia/v0.6/JavaCall/src/core.jl:281
 [3] jcall(::Type{JavaCall.JavaObject{Symbol("edu.stanford.nlp.util.CoreMap")}}, ::String, ::Type{T} where T, ::Tuple{DataType}, ::JavaCoreNLP.Annotation, ::Vararg{JavaCoreNLP.Annotation,N} where N) at /home/john/.julia/v0.6/JavaCall/src/core.jl:128

```

Some concrete questions–

1. How to construct the jcall for “get”.
2. What type does the jcall for “get” return? It should be whatever is stored as the value in the object.
3. How to distinguish between document.get, sentence.get, etc in the jcall?
4. How to construct the jcall so that it accepts a `List<CoreMap>` in return?

Hope that’s clear enough. Thanks again for the help.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 12, 2017, 11:53am UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/14 "2017-07-12T11:53:56Z")

</div>

> [@aether](#):
>
> Import CoreMap into Julia. I tried–  
> JCoreMap = @jimport edu.stanford.nlp.util.CoreMap  
> and it worked error-free in Julia.

Correct.

> Act on doc::Annotation using CoreMap’s “get” method to obtain a List called, e.g., sentences.

Not quite. Let’s break it down.

```java
// Java
document.get(...)

```

Here we call method `get` of object `document` which has type `Annotation` in Java. In Julia we have a handle to such an object in `doc.jann` and its type, again in our Julia application, is `JAnnotation` (while Julia’s `Annotation` is a wrapper around this handle). In other words:

```julia
struct Annotation # <-- this is a Julia wrapper
    jann::JAnnotation # <-- this is the handle to Java object or type edu.stanford.nlp.pipeline.Annotation 
                        # which we aliased in Julia as JAnnotation
end

```

So the basic call should be:

```julia
jcall(
   doc.jann, # <-- handle to Java object
   "get", # <-- method name
    ..., # return type, ignore for now,
    (...), # argument types
    ... # actual arguments
)

```

Note, that `get` is a method inherited from `ArrayCoreMap` and is defined [here](https://github.com/stanfordnlp/CoreNLP/blob/master/src/edu/stanford/nlp/util/ArrayCoreMap.java#L115). It has signature:

```java
<VALUE> VALUE get(Class<? extends Key<VALUE>> key)

```

Whoa! Looks unreadable for non-Java people, right? Let’s further break it down:

- `<VALUE>` is a type parameter, similar to `<typename VALUE>` in C++ templates or `... where VALUE` in Julia
- `VALUE` means that we return this exact type
- `Class<VALUE>` (I simplified a bit) means that `get` takes a single argument of Java type `Class<VALUE>`

We pass `SentencesAnnotation.class` to this `get` which is a value of type `Class<SentencesAnnotation>`. From it we can infer that `VALUE` in this case is `SentencesAnnotation`! Method signature thus is:

```java
SentencesAnnotation get(Class<SentencesAnnotation> key)

```

It’s interesting to note that `SentencesAnnotation` actually implements interface `List<CoreMap>` which we see as a return type in Java code:

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

```

Ok, we understood what it all means in Java, but how should it look like in Julia? It’s a bit more tricky question that boils down to:

- what signature this method has in JVM itself (because type parameters don’t actually exist after compilation)
- how to specify type of `Class<SentencesAnnotation>` since JavaCall doesn’t support generics too

To answer these questions I need to inspect `JAnnotation` object that I can’t do right now. Would you mind running the following for me?

```julia
JavaCall.listmethods(doc.jann, "get")

```

* * *

And while I wait for the result of the previous code I will address your questions (3) and (4) (I hope previous explanation shed some light on questions (1) and (2)).

> How to distinguish between document.get, sentence.get, etc in the jcall?

As simple as

```
jcall(jann, ...)
jcall(jsentence, ...)
# etc.

```

The first argument is always an object you call method on. Literally, `obj.method(...)` is translated into `jcall(jobj, "method", ...)`.

> How to construct the jcall so that it accepts a List\< CoreMap \> in return?

It depends on the actual method signature in JVM. The tricky part is that what you see in Java code doesn’t always correspond one-to-one to what is really created in JVM. As I mentioned earlier, JVM knows nothing about type parameters, so definitely there’s no information about `CoreMap` in there. Moreover, there may be nothing about `List` in JVMs signature for that method, but instead any interface that extends `List` or any class that implements it.

It’s not the easiest part of working with JVM. Fortunately, it’s actually rarely needed to dive so deep - as you will see soon, most of the time you just construct objects and call `jcall` on clear method signature from Java docs.

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 12, 2017, 12:01pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/15 "2017-07-12T12:01:31Z")

</div>

```julia
julia> JavaCall.listmethods(doc.jann, "get")
1-element Array{JavaCall.JavaObject{Symbol("java.lang.reflect.Method")},1}:
 java.lang.Object get(java.lang.Class)

```

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 12, 2017, 12:41pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/16 "2017-07-12T12:41:01Z")

</div>

Read and understood, **thanks**. I still don’t see how to write down the last three arguments of the `jcall` call for `document.get`,` sentences.get`, etc. But I understand there may be more answer coming based on `JavaCall.listmethods(doc.jann, "get")` that you asked me to run. So I’m waiting for now.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 12, 2017, 12:52pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/17 "2017-07-12T12:52:29Z")

</div>

Looks good! From it we see that:

- return type is just a plain `java.lang.Object` aliased as `JObject` in JavaCall
- method accepts an instance of `java.lang.Class` or `JClass` in JavaCall

Our `jcall` now looks like:

```julia
jcall(doc.jann, "get", JObject, (JClass,), ...)

```

The only thing that we don’t have yet is an instance of `java.lang.Class<SentencesAnnotation>`. We can do it by calling the following in Java:

```java
Class.forName("edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation")

```

or equivalently in Julia:

```julia
jcall(JClass, "forName", JClass, (JString,), "edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation")

```

Finally, the Java code:

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

```

is translated into:

```julia
jsentences_annotation_class = jcall(JClass, "forName", JClass, (JString,), "edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation")
sentences = jcall(doc.jann, "get", JObject, (JClass,), jsentences_annotation_class)

```

Please run it and report if there are any issues. If everything is fine, I’ll move to iterating over the list of sentences (which is much simpler, but requires knowledge of Java collections).

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [July 12, 2017, 1:35pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/18 "2017-07-12T13:35:36Z")

</div>

The `forName` call failed as follows–

```julia
julia> jcall(JClass, "forName", JClass, (JString,), "edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation")
Exception in thread "main" java.lang.ClassNotFoundException: edu/stanford/nlp/ling/CoreAnnotations/SentencesAnnotation
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
ERROR: Error calling Java: java.lang.ClassNotFoundException: edu/stanford/nlp/ling/CoreAnnotations/SentencesAnnotation
Stacktrace:
 [1] geterror(::Bool) at /home/john/.julia/v0.6/JavaCall/src/core.jl:265
 [2] _jcall(::JavaCall.JavaMetaClass{Symbol("java.lang.Class")}, ::Ptr{Void}, ::Ptr{Void}, ::Type{T} where T, ::Tuple{DataType}, ::String, ::Vararg{String,N} where N) at /home/john/.julia/v0.6/JavaCall/src/core.jl:223
 [3] jcall(::Type{JavaCall.JavaObject{Symbol("java.lang.Class")}}, ::String, ::Type{T} where T, ::Tuple{DataType}, ::String, ::Vararg{String,N} where N) at /home/john/.julia/v0.6/JavaCall/src/core.jl:131

```

Per google, maybe that’s a problem with the classpath. Not sure how that works for Julia.

I’m also wondering why this is a `jcall` and not a `@jimport` like–

`jsentences_annotation_class = @jimport edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation`

since the purpose is to create a Jobject that matches the `SentencesAnnotation` class. (I thought that’s what `@jimport` does.) Also, the earlier examples (pipeline and annotator) first called `@jimport` and then used the resulting object in the `jcall` call, as you explain above.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 12, 2017, 2:23pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/19 "2017-07-12T14:23:31Z")

</div>

Ah, it’s a bit more interesting. It seems like `SentencesAnnotation` is a so-called “inner class”, i.e. class defined inside another class - `CoreAnnotations `. So I guess the correct syntax is (not a `$` in the name):

```
jcall(JClass, "forName", JClass, (JString,), "edu.stanford.nlp.ling.CoreAnnotations$SentencesAnnotation")

```

* * *

Although these are not issues with your call, your concerns still deserve explanation:

> Per google, maybe that’s a problem with the classpath. Not sure how that works for Julia.

You specify classpath (e.g. list of JAR files to include) in `JavaCall.init()`. In this project I made a trick: built a single large JAR that encapsulates all libraries you need. If you ever want to add more libraries, edit `JavaCoreNLP/jvm/corenlp-wrapper/pom.xml`, add these libraries as dependencies and rebuild using either `mvn clean package` from a shell or `Pkg.build("JavaCoreNLP")` from a Julia REPL.

> I’m also wondering why this is a jcall and not a @jimport like–

This is one thing that sometimes blows my mind too. The reason is that you have to work with 4 different kinds of objects - Java types, Java objects, Julia types and Julia objects. Let’s start with the Java side.

In Java you normally work with objects, i.e. instances of classes. E.g. in (Java):

```java
Foo foo = new Foo();

```

`Foo` is the name of the class and `foo` is an instance of that class. Just like `int` is the name of a type and `42` is an object of that type.

In Julia syntax is different, but in general idea is the same:

```julia
bar = Bar()

```

`Bar` - name of a type, `bar` - an object of that type.

JavaCall let’s you treat Java classes (types of Java objects) just like you would normally do with other types:

```julia
JFoo = @jimport Foo # import Java class Foo
jfoo = JFoo(()) # create an object of Java class Foo

```

This is how you normally use JavaCall and it should be pretty straightforward, right?

* * *

But both - in Julia and Java - types/classes are themselves objects! In Java each class is an instance of `java.lang.Class` (e.g. `java.lang.Class<Foo>`) and in Julia each type is an object of type `DataType`. So when you have a name of a class/type at hand, you can treat them either as **types** or **objects**. For example in Java:

```java
void myFunction(Foo foo) { ... } // <-- Foo acts as type, i.e. qualifier of objects that can be passed to the function

Class<Foo> fooClass = Foo.class // <-- Foo acts as an object. You can create an instance of that class
Class<Foo> fooClass = Class.forName("Foo") // or call class methods (as opposed to instance methods) 

```

When in Java want to pass `SentencesAnnotation` to a function, so we need this class as an object, not as a type. In Java we can get an it as an object using either of the 2 syntaxes:

```julia
SentencesAnnotation.class
Class.forName("Foo")

```

Unfortunately, the first one relies on an object field which JavaCall can’t read (or it already can?), so we are left with the second option:

```julia
jcall(JClass, "forName", JClass, (JString,), "Foo")

```

* * *

To summarize:

- `@jimport` makes Java class available as a type; this is how you normally work with Java classes
- `jcall(JClass, "forName", JClass, (JString,), ...)` creates an object of Java class and returns a pointer to it

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 12, 2017, 2:28pm UTC](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714/20 "2017-07-12T14:28:44Z")

</div>

By the way, try (insert any existing class instead of `Foo`):

```julia
JFoo = @jimport Foo
typeof(JFoo) # DataType

foo = Foo(())
typeof(foo) # JavaObject{:Foo}

foo_class = jcall(JClass, "forName", JClass, (JString,), "Foo")
typeof(foo_class) . # JavaObject{Symbol("java.lang.Class")}

```

[Next page](https://discourse.julialang.org/t/corenlp-base-name-conflict/4714.md?page=2)
