Search in sources :

Example 1 with ProcessingException

use of org.opensextant.processing.ProcessingException in project Xponents by OpenSextant.

the class CSVFormatter method start.

@Override
public void start(String nm) throws ProcessingException {
    try {
        buildSchema();
        createOutputStreams();
        writer = new CsvMapWriter(fio, CsvPreference.EXCEL_PREFERENCE);
        writer.writeHeader(header);
    } catch (Exception err) {
        throw new ProcessingException("Failed to launch", err);
    }
}
Also used : CsvMapWriter(org.supercsv.io.CsvMapWriter) ConfigException(org.opensextant.ConfigException) ProcessingException(org.opensextant.processing.ProcessingException) ProcessingException(org.opensextant.processing.ProcessingException)

Example 2 with ProcessingException

use of org.opensextant.processing.ProcessingException in project Xponents by OpenSextant.

the class GISDataFormatter method start.

/**
     * Start output.
     */
@Override
public void start(String containerName) throws ProcessingException {
    /**
         * apply default GIS data model
         */
    if (this.gisDataModel == null) {
        setGisDataModel();
    }
    try {
        createOutputStreams();
    } catch (Exception create_err) {
        throw new ProcessingException(create_err);
    }
    DocumentStart ds = new DocumentStart(doc_type);
    this.os.write(ds);
    this.os.write(gisDataModel.getSchema());
    ContainerStart containerStart = new ContainerStart();
    containerStart.setType("Folder");
    containerStart.setName(containerName);
    this.os.write(containerStart);
}
Also used : DocumentStart(org.opensextant.giscore.events.DocumentStart) ContainerStart(org.opensextant.giscore.events.ContainerStart) ConfigException(org.opensextant.ConfigException) ProcessingException(org.opensextant.processing.ProcessingException) ProcessingException(org.opensextant.processing.ProcessingException)

Example 3 with ProcessingException

use of org.opensextant.processing.ProcessingException in project Xponents by OpenSextant.

the class BasicGeoTemporalProcessing method createFormatter.

/**
     * The default formatter
     */
public static AbstractFormatter createFormatter(String outputFormat, Parameters plist) throws IOException, ProcessingException {
    if (plist.isdefault) {
        throw new ProcessingException("Caller is required to use non-default Parameters; " + "\nat least set the output options, folder, jobname, etc.");
    }
    AbstractFormatter formatter = (AbstractFormatter) FormatterFactory.getInstance(outputFormat);
    if (formatter == null) {
        throw new ProcessingException("Wrong formatter?");
    }
    formatter.setParameters(plist);
    formatter.setOutputFilename(plist.getJobName() + formatter.outputExtension);
    return formatter;
}
Also used : AbstractFormatter(org.opensextant.output.AbstractFormatter) ProcessingException(org.opensextant.processing.ProcessingException)

Example 4 with ProcessingException

use of org.opensextant.processing.ProcessingException in project Xponents by OpenSextant.

the class BasicGeoTemporalProcessing method setup.

/**   Ideally you should separate your one-time initialization steps, configuring your extractors
     * apart from the repetitive steps of setting up Jobs and Inputs.   Outputs you might setup once
     * for the entire JVM session, or it may be something you do periodically.  In summary:
     *
     * configure separately:
     *   a) extractors, converters
     *   b) job inputs and parameters
     *   c) output formatters
     *   d) other resources, e.g., filters
     */
public void setup(String inFile, List<String> outFormats, String outFile, String tempDir) throws ConfigException, ProcessingException, IOException {
    params.isdefault = false;
    if (!validateParameters(inFile, outFormats, outFile, tempDir, params)) {
        throw new ProcessingException("VALIDATION ERRORS: " + runnerMessage.toString());
    }
    // If you are dead-sure you want only coordinates from text, then just use XCoord.
    // Otherwise SimpleGeocoder does both coords + names.
    // 
    //XCoord xcoord = new XCoord();
    //xcoord.configure();
    //this.addExtractor(xcoord);
    // Testing only
    params.tag_places = true;
    params.tag_coordinates = true;
    params.output_countries = false;
    PlaceGeocoder geocoder = new PlaceGeocoder();
    geocoder.enablePersonNameMatching(true);
    geocoder.setParameters(params);
    geocoder.configure();
    this.addExtractor(geocoder);
    XTemporal xtemp = new XTemporal();
    xtemp.configure();
    this.addExtractor(xtemp);
    converter = new XText();
    converter.enableHTMLScrubber(false);
    converter.enableSaving(true);
    converter.enableOverwrite(false);
    converter.setConversionListener(this);
    // 
    if (tempDir != null) {
        converter.getPathManager().setConversionCache(tempDir);
    } else {
        converter.enableSaving(false);
    }
    try {
        converter.setup();
    } catch (IOException ioerr) {
        throw new ConfigException("Document converter could not start", ioerr);
    }
    this.params.inputFile = inFile.trim();
    this.params.outputFile = outFile.trim();
    if (outFormats != null) {
        for (String fmt : outFormats) {
            params.addOutputFormat(fmt);
            AbstractFormatter formatter = createFormatter(fmt, params);
            formatter.overwrite = overwriteOutput;
            this.addFormatter(formatter);
            //if (formatter instanceof CSVFormatter) {
            //    formatter.addField(OpenSextantSchema.FILEPATH.getName());
            //    formatter.addField(OpenSextantSchema.MATCH_TEXT.getName());
            // }
            formatter.start(params.getJobName());
        }
    }
}
Also used : PlaceGeocoder(org.opensextant.extractors.geo.PlaceGeocoder) XTemporal(org.opensextant.extractors.xtemporal.XTemporal) XText(org.opensextant.xtext.XText) ConfigException(org.opensextant.ConfigException) IOException(java.io.IOException) AbstractFormatter(org.opensextant.output.AbstractFormatter) ProcessingException(org.opensextant.processing.ProcessingException)

Example 5 with ProcessingException

use of org.opensextant.processing.ProcessingException in project Xponents by OpenSextant.

the class TweetGeocoder method createFormatter.

/**
     * The default formatter
     */
public static GISDataFormatter createFormatter(String outputFormat, Parameters p) throws IOException, ProcessingException {
    if (p.isdefault) {
        throw new ProcessingException("Caller is required to use non-default Parameters; " + "\nat least set the output options, folder, jobname, etc.");
    }
    GISDataFormatter formatter = (GISDataFormatter) FormatterFactory.getInstance(outputFormat);
    if (formatter == null) {
        throw new ProcessingException("Wrong formatter?");
    }
    formatter.setParameters(p);
    // formatter.setOutputDir(params.outputDir);
    formatter.setOutputFilename(p.getJobName() + formatter.outputExtension);
    return formatter;
}
Also used : GISDataFormatter(org.opensextant.output.GISDataFormatter) ProcessingException(org.opensextant.processing.ProcessingException)

Aggregations

ProcessingException (org.opensextant.processing.ProcessingException)6 ConfigException (org.opensextant.ConfigException)3 AbstractFormatter (org.opensextant.output.AbstractFormatter)2 IOException (java.io.IOException)1 PlaceGeocoder (org.opensextant.extractors.geo.PlaceGeocoder)1 XTemporal (org.opensextant.extractors.xtemporal.XTemporal)1 ContainerStart (org.opensextant.giscore.events.ContainerStart)1 DocumentStart (org.opensextant.giscore.events.DocumentStart)1 GISDataFormatter (org.opensextant.output.GISDataFormatter)1 XText (org.opensextant.xtext.XText)1 CsvMapWriter (org.supercsv.io.CsvMapWriter)1