I am using Eclipse actually. I am working with a jena model and can print out my triples. The problem that I am running into is adding a property to my model in a second class; most properties are added in the Parser class, except for the annotation labels. I am calling a third party api(?TextAnnotations.java) and wish to load the labels into my model there.
This is a jena question. I do not know how to pass the model in a parameter list, and have the object returned to Parser.java. Sorry to be persistent, but this is how I perceive the problem. Mona On Wed, Jan 29, 2014 at 1:51 PM, Rob Vesse <rve...@dotnetrdf.org> wrote: > Your code is not complete and you haven't shown how you run your code > (i.e. command line invocation) so we can only guess at the cause of the > problem > > However your error is a standard Java compiler error completely unrelated > to Jena and indicates one of two things: > > 1 - You do not have the appropriate import statements at the start of your > Java file > 2 - You're trying to run a single Java file and don't have your compiled > code for those classes available on the class path > > Rob > > On 29/01/2014 13:03, "Mona Salem" <monasalem...@gmail.com> wrote: > > >Hi again > >My project is basically: 1) to come in with an abstract/ scientific > >article, 2) call an existing Annotator from Parser.java, 3) get good > >labels, and 4) return model with all the new labels to Parser.java. > > > >I have created my jena model in Parser.java, and wish to call > >TextAnnotation.java to load the "preferred labels" into my model, via the > >property AnnotationLabel in TextAnnotation.java. > >The labels are loaded in the printAnnotations method of class > >TextAnnotation. (I need to return model back to Parser.java.) > >I wish to use only one model. I am running into compile time errors. > > > >THANKS in ADVANCE for your help. > >Mona > > > >import com.hp.hpl.jena.rdf.model.Model; > >import com.hp.hpl.jena.rdf.model.ModelFactory; > >import com.hp.hpl.jena.rdf.model.Resource; > >import com.hp.hpl.jena.rdf.model.Property; > > > >public class Parser { > > public static Model model = ModelFactory.createDefaultModel(); > > > > /* create the Resource, using the product URI */ > > Resource softwareproduct = > >model.createResource(urlAddress); > > > > //create the properties > > > > Property extracteddata = model.createProperty(" > >http://www.mydirectory.com/softwareproduct#extracteddata"); > > > > Property annotationLabel = model.createProperty(" > >http://www.mydirectory.com/softwareproduct#softwareannotation"); > >... > > > > SAXparsingExtractedText saxparser = new > >SAXparsingExtractedText(); > > abstractinfo = > >saxparser.parseDocument(urlAddress); > > > > softwareproduct.addProperty(extracteddata, > >abstractinfo); > > > > //-------> I call the TEXT ANNOTATOR with abstractinfo > >and model (??) and url address > > > > TextAnnotation annotateText = new > >TextAnnotation(); > > annotateText.stringToAnnotate(abstractinfo, > >model, urlAddress); > > > > > >} > > > > > >import com.fasterxml.jackson.core.JsonProcessingException; > >import com.fasterxml.jackson.databind.JsonNode; > >import com.fasterxml.jackson.databind.ObjectMapper; > >import com.hp.hpl.jena.rdf.model.Model; > >import com.hp.hpl.jena.rdf.model.Property; > >import com.hp.hpl.jena.rdf.model.Resource; > > > > > >public class TextAnnotation { > > > > static final String REST_URL = "http://data.bioontology.org"; > > static final ObjectMapper mapper = new ObjectMapper(); > > > > public void stringToAnnotate(String abstractInfo, Model model2, String > >URLaddress) throws UnsupportedEncodingException { > > > >String textToAnnotate = URLEncoder.encode(abstractInfo, "UTF-8"); > > > >Resource SoftwareProduct = model2.createResource(URLaddress); > >Property AnnotationLabel = model2.createProperty(" > >http://www.mydirectory.com/softwareproduct#softwareannotation"); > > // Get just annotations > > JsonNode annotations = jsonToNode(get(REST_URL + > >"/annotator?ontologies=NCIT&text=" + textToAnnotate)); > > printAnnotations(annotations); > > > > } > > > > private model2 printAnnotations(JsonNode annotations) { > > for (JsonNode annotation : annotations) { > > // Get the details for the class that was found in the > >annotation and print > > JsonNode classDetails = > >jsonToNode(get(annotation.get("annotatedClass").get("links").get("self").a > >sText())); > > > > //Don't print "preferred Labels", load "prefLabels" into the > >model > > // System.out.println("\tprefLabel: " + > >classDetails.get("prefLabel").asText()); > > > > SoftwareProduct.addProperty(AnnotationLabel, > >classDetails.get("prefLabel").asText()); > > > > > > > > } > > } > > } > > } > > > > private static JsonNode jsonToNode(String json) { > > JsonNode root = null; > > try { > > root = mapper.readTree(json); > > } catch (JsonProcessingException e) { > > e.printStackTrace(); > > } catch (IOException e) { > > e.printStackTrace(); > > } > > return root; > > } > > > > private static String get(String urlToGet) { > > URL url; > > HttpURLConnection conn; > > BufferedReader rd; > > String line; > > String result = ""; > > try { > > url = new URL(urlToGet); > > conn = (HttpURLConnection) url.openConnection(); > > conn.setRequestMethod("GET"); > > conn.setRequestProperty("Authorization", "apikey token=" + > >API_KEY); > > conn.setRequestProperty("Accept", "application/json"); > > rd = new BufferedReader( > > new InputStreamReader(conn.getInputStream())); > > while ((line = rd.readLine()) != null) { > > result += line; > > } > > rd.close(); > > } catch (Exception e) { > > e.printStackTrace(); > > } > > return result; > > } > >} > > > > > >Compilation errors: > >Exception in thread "main" java.lang.Error: Unresolved compilation > >problems: > >SoftwareProduct cannot be resolved > >AnnotationLabel cannot be resolved to a variable > > > >at TextAnnotation.printAnnotations(TextAnnotation.java:47) > >at TextAnnotation.stringToAnnotate(TextAnnotation.java:32) > >at Parser.getTitle(Parser.java:291) > >at Parser.getAllUrlNames(Parser.java:118) > >at Parser.main(Parser.java:723) > > > > > > > >On Mon, Jan 27, 2014 at 3:36 PM, Joshua TAYLOR > ><joshuaaa...@gmail.com>wrote: > > > >> You can pass models as parameters to methods (just like any other Java > >> object). The code in this message looks like it may have been mangled > >> on its way to the list. It's certainly not in a compilable state at > >> the moment. E.g., lines like > >> > >> Product.addProperty(category_n, classDetails.get( ); > >> > >> don't even have balanced parentheses. It will be much easier to see > >> what the problem is if you can provide a minimal example that other > >> people can use to reproduce the error, and if you show what error > >> you're actually getting. E.g., when you say that "[you] tried > >> passing the model in a parameter list from Parser.java. It did not > >> work: `Annotator.printAnnotations(model).`", what do you mean that it > >> didn't work? Did you get a compilation error? Were you able to run > >> it, but it produced different results than what you'd been expected? > >> Or something else entirely? > >> > >> > >> > >> On Mon, Jan 27, 2014 at 6:10 PM, Mona Salem <monasalem...@gmail.com> > >> wrote: > >> > Hi > >> > > >> > I am a newbie to Jena. > >> > > >> > I want to be able to add rdf statements to my model in two different > >> .java > >> > classes; ie Parser.java and Annotator.java > >> > > >> > I did the following: > >> > > >> > public class Parser { > >> > > >> > > >> > > >> > public static Model model = ModelFactory.createDefaultModel(); > >> > > >> > > >> > > >> > > >> > > >> > Resource Product = model.createResource(ItemAddress); > >> > > >> > > >> > > >> > //create the properties > >> > > >> > Property category1 = model.createProperty("http: .); > >> > > >> > Property category2 = model.createProperty("http: .); > >> > > >> > Property category3 = model.createProperty("http: .); > >> > > >> > . > >> > > >> > . > >> > > >> > . > >> > > >> > Property category_n = model.createProperty("http: .); > >> > > >> > > >> > > >> > //add object > >> > > >> > Product.addProperty(category1, ); > >> > > >> > Product.addProperty(category2, ); > >> > > >> > . > >> > > >> > . > >> > > >> > . > >> > > >> > > >> > > >> > } > >> > > >> > > >> > > >> > I want to load values for category_n in a method of the second class: > >> > > >> > > >> > > >> > public class Annotator{ > >> > > >> > > >> > > >> > private static void printAnnotations(JsonNode annotations){ > >> > > >> > for (JsonNode annotation : annotations){ > >> > > >> > > >> > > >> > System.out.println(" something here"); > >> > > >> > > >> > > >> > Product.addProperty(category_n, classDetails.get( ); > >> > > >> > > >> > > >> > } > >> > > >> > } > >> > > >> > > >> > > >> > Note that the loop in the printAnnotations method will create multiple > >> rdf > >> > statements with same pair resource/predicate and multiple objects. > >> > > >> > > >> > > >> > I tried passing the model in a parameter list from Parser.java. It > >>did > >> not > >> > work > >> > > >> > Annotator.printAnnotations(model). > >> > > >> > > >> > > >> > I thought making the model public would make this work. > >> > > >> > > >> > > >> > Should I use an array in Annotator to collect the values in the loop? > >> > > >> > > >> > > >> > Thanks for the help. > >> > > >> > Mona > >> > > >> > > >> > > >> > >> > >> > >> -- > >> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/ > >> > > > > >