Skip to content

Wrapper for easily accessing FrameNet semantic parsing via SEMAFOR parser in Java

License

Notifications You must be signed in to change notification settings

wojtuch/SEMA4J

 
 

Repository files navigation

SEMA4J

SEMA4J is a Java wrapper for easily accessing FrameNet semantic parsing by the SEMAFOR parser. Since this parser is primarly designed as a command line tool, this wrapper gives you easy programmatic access to FrameNet semantic parsing. It is also very easy to configure and get started with, let's check it out.

#Example First of all, create a FrameNetAnnotator instance by specifying your JAVA_HOME installation path.

FrameNetAnnotator fnAnno = new FrameNetAnnotator(javaHomePath);

Instantiating the FrameNetAnnotator that way sets up standard options for the parser. If you want to set specific options, create a FrameNetOptions object and then create the annotator.

FrameNetOptions fnOpts = new FrameNetOptions(true, true, false, FrameNetOptions.DECODING_TYPE_BEAM,
                                              FrameNetOptions.NO_GOLD_FILES, javaHomePath);
FrameNetAnnotator fnAnno = new FrameNetAnnotator(fnOpts);

Once you have created the annotator, you can start with the semantic parsing of strings. This can be achieved, by simply calling the corresponding fetchFNResult methods as shown below. This method returns a list with all frames invoked by the assigned string. Afterwards you can access all properties of a frame and also iterate through the frame elements.

List<Frame> frames = fnAnno.fetchFNResult("Send you application to the university");
for(Frame frame : frames) {
//Do something with the frame
  for(FElement felement : frame.iterator()) {
    //Do something with frame element
  }
}

Often you want to collect multiple sentences to be annotated at once. Simply add them to the cache. From the results map, you can easily access to Frame list for each annotated string.

List<String> sentences = new ArrayList<>();
sentences.add("Wait for the results");
sentences.add("Receive acknowledgement from the university")
//Add to cache
fnAnno.addToCache(sentences);
//Get annotation results
HashMap<String, List<Frame>> frameAnnos = fnAnno.fetchFNResultsFromCache(sentence);
//Access frames for "Wait for the results"
List<Frame> frames = frameAnnos.get(sentences.get(0));

About

Wrapper for easily accessing FrameNet semantic parsing via SEMAFOR parser in Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%