This page is no longer maintained — Please continue to the home page at www.scala-lang.org

overloaded method call problem

1 reply
Pavel Shapkin
Joined: 2009-01-14,
User offline. Last seen 42 years 45 weeks ago.

Hello,

I am new to Scala. I'm trying to access Jena Semantic Web Framework from
Scala. The following Java code was taken from Jena Tutorial and works fine:

package hello;

import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class HelloWorld {

public static void main(String[] args)
{
Model m = ModelFactory.createDefaultModel();
String NS = "http://example.com/test/";
Resource r = m.createResource(NS + "r");
Property p = m.createProperty(NS + "p");
r.addProperty(p, "hello world", XSDDatatype.XSDstring);
m.write(System.out, "Turtle");
}

}

I've created its Scala equivalent and it doesn't work:

package hello

import com.hp.hpl.jena.datatypes.xsd.XSDDatatype
import com.hp.hpl.jena.rdf.model.Model
import com.hp.hpl.jena.rdf.model.ModelFactory
import com.hp.hpl.jena.rdf.model.Property
import com.hp.hpl.jena.rdf.model.Resource

object HelloWorld extends Application {
val m = ModelFactory.createDefaultModel
val NS = "http://example.com/test/"
val r = m.createResource(NS + "r")
val p = m.createProperty(NS + "p")
r.addProperty(p, "hello world",XSDDataType.XSDstring)
m.write(System.out)
}

Compiler throws "wrong number of arguments" errors for overloaded
methods createResource, addProperty and Model.write. Am I doing
something wrong?

Sebastien Bocq
Joined: 2008-12-18,
User offline. Last seen 42 years 45 weeks ago.
Re: overloaded method call problem
Your example works fine with scala 2.7.3.final and jena-2.5.7, the only difference is that I had to use XSDDatatype instead of XSDDataType.

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://example.com/test/" >
  <rdf:Description rdf:about="http://example.com/test/r">
    <j.0:p rdf:datatype="http://www.w3.org/2001/XMLSchema#string">hello world</j.0:p>
  </rdf:Description>
</rdf:RDF>

It's probably something wrong with your environment.

-Sebastien

2009/1/14 Pavel Shapkin <psnet [at] yandex [dot] ru>
Hello,

I am new to Scala. I'm trying to access Jena Semantic Web Framework from
Scala. The following Java code was taken from Jena Tutorial and works fine:

package hello;

import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class HelloWorld {

       public static void main(String[] args)
       {
         Model m = ModelFactory.createDefaultModel();
         String NS = "http://example.com/test/";
         Resource r = m.createResource(NS + "r");
         Property p = m.createProperty(NS + "p");
         r.addProperty(p, "hello world", XSDDatatype.XSDstring);
         m.write(System.out, "Turtle");
       }
       
}

I've created its Scala equivalent and it doesn't work:

package hello

import com.hp.hpl.jena.datatypes.xsd.XSDDatatype
import com.hp.hpl.jena.rdf.model.Model
import com.hp.hpl.jena.rdf.model.ModelFactory
import com.hp.hpl.jena.rdf.model.Property
import com.hp.hpl.jena.rdf.model.Resource

object HelloWorld extends Application {
  val m = ModelFactory.createDefaultModel
  val NS = "http://example.com/test/"
  val r = m.createResource(NS + "r")
  val p = m.createProperty(NS + "p")
  r.addProperty(p, "hello world",XSDDataType.XSDstring)
  m.write(System.out)
}

Compiler throws "wrong number of arguments" errors for overloaded
methods createResource, addProperty and Model.write. Am I doing
something wrong?


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland