1   package eu.fbk.dkm.pikes.naflib;
2   
3   import java.io.File;
4   
5   import com.google.common.base.Charsets;
6   import com.google.common.io.Files;
7   
8   import eu.fbk.utils.core.EasySpan;
9   import org.slf4j.Logger;
10  import org.slf4j.LoggerFactory;
11  
12  import ixa.kaflib.KAFDocument;
13  
14  import eu.fbk.utils.core.CommandLine;
15  
16  /**
17   * Created by alessio on 25/03/15.
18   */
19  
20  public class NafOffsetReader {
21  
22  	private static final Logger LOGGER = LoggerFactory.getLogger(NafOffsetReader.class);
23  
24  	public static void main(String[] args) {
25  		final CommandLine cmd = CommandLine
26  				.parser()
27  				.withName("naf-offset-reader")
28  				.withHeader("Read offset from a file")
29  				.withOption("s", "start", "starting offset", "NUM", CommandLine.Type.INTEGER, true, false, true)
30  				.withOption("e", "end", "ending offset", "NUM", CommandLine.Type.INTEGER, true, false, true)
31  				.withOption("n", "naf", "file", "FILE", CommandLine.Type.FILE_EXISTING, true, false, true)
32  				.withLogger(LoggerFactory.getLogger("eu.fbk.fssa")).parse(args);
33  
34  		final Integer start = cmd.getOptionValue("s", Integer.class);
35  		final Integer end = cmd.getOptionValue("e", Integer.class);
36  		final File nafFile = cmd.getOptionValue("n", File.class);
37  
38  		try {
39  			String text;
40  			try {
41  				KAFDocument document = KAFDocument.createFromFile(nafFile);
42  				text = document.getRawText();
43  			} catch (Exception e) {
44  				text = Files.toString(nafFile, Charsets.UTF_8);
45  			}
46  			EasySpan span = new EasySpan(start, end);
47  			String piece = span.apply(text, false);
48  
49  			System.out.println(span);
50  			System.out.println("===" + piece + "===");
51  		} catch (Exception e) {
52  			LOGGER.error(e.getMessage());
53  		}
54  	}
55  }