Example usage for java.nio.file Paths get

List of usage examples for java.nio.file Paths get

Introduction

In this page you can find the example usage for java.nio.file Paths get.

Prototype

public static Path get(URI uri) 

Source Link

Document

Converts the given URI to a Path object.

Usage

From source file:au.org.ands.vocabs.toolkit.db.PopulateAccessPoints.java

/**
 * Main program./*from ww  w  . j a v  a 2  s .c  o m*/
 * @param args Command-line arguments
 */
public static void main(final String[] args) {
    // Create prefixes that both end with a slash, so that
    // they can be substituted for each other.
    String sparqlPrefix = sparqlPrefixProperty;
    if (!sparqlPrefix.endsWith("/")) {
        sparqlPrefix += "/";
    }
    String sesamePrefix = sesamePrefixProperty;
    if (!sesamePrefix.endsWith("/")) {
        sesamePrefix += "/";
    }
    sesamePrefix += "repositories/";
    System.out.println("sparqlPrefix: " + sparqlPrefix);
    System.out.println("sesamePrefix: " + sesamePrefix);
    List<Version> versions = VersionUtils.getAllVersions();
    for (Version version : versions) {
        System.out.println(version.getId());
        System.out.println(version.getTitle());
        String data = version.getData();
        System.out.println(data);
        JsonNode dataJson = TaskUtils.jsonStringToTree(data);
        JsonNode accessPoints = dataJson.get("access_points");
        if (accessPoints != null) {
            System.out.println(accessPoints);
            System.out.println(accessPoints.size());
            for (JsonNode accessPoint : accessPoints) {
                System.out.println(accessPoint);
                AccessPoint ap = new AccessPoint();
                ap.setVersionId(version.getId());
                String type = accessPoint.get("type").asText();
                JsonObjectBuilder jobPortal = Json.createObjectBuilder();
                JsonObjectBuilder jobToolkit = Json.createObjectBuilder();
                String uri;
                switch (type) {
                case AccessPoint.FILE_TYPE:
                    ap.setType(type);
                    // Get the path from the original access point.
                    String filePath = accessPoint.get("uri").asText();
                    // Save the last component of the path to use
                    // in the portal URI.
                    String downloadFilename = Paths.get(filePath).getFileName().toString();
                    if (!filePath.startsWith("/")) {
                        // Relative path that we need to fix up manually.
                        filePath = "FIXME " + filePath;
                    }
                    jobToolkit.add("path", filePath);
                    ap.setPortalData("");
                    ap.setToolkitData(jobToolkit.build().toString());
                    // Persist what we have ...
                    AccessPointUtils.saveAccessPoint(ap);
                    // ... so that now we can get access to the
                    // ID of the persisted object with ap2.getId().
                    String format;
                    if (downloadFilename.endsWith(".trig")) {
                        // Force TriG. This is needed for some legacy
                        // cases where the filename is ".trig" but
                        // the format has been incorrectly recorded
                        // as RDF/XML.
                        format = "TriG";
                    } else {
                        format = accessPoint.get("format").asText();
                    }
                    jobPortal.add("format", format);
                    jobPortal.add("uri", downloadPrefixProperty + ap.getId() + "/" + downloadFilename);
                    ap.setPortalData(jobPortal.build().toString());
                    AccessPointUtils.updateAccessPoint(ap);
                    break;
                case AccessPoint.API_SPARQL_TYPE:
                    ap.setType(type);
                    uri = accessPoint.get("uri").asText();
                    jobPortal.add("uri", uri);
                    if (uri.startsWith(sparqlPrefix)) {
                        // One of ours, so also add a sesameDownload
                        // endpoint.
                        AccessPoint ap2 = new AccessPoint();
                        ap2.setVersionId(version.getId());
                        ap2.setType(AccessPoint.SESAME_DOWNLOAD_TYPE);
                        ap2.setPortalData("");
                        ap2.setToolkitData("");
                        // Persist what we have ...
                        AccessPointUtils.saveAccessPoint(ap2);
                        // ... so that now we can get access to the
                        // ID of the persisted object with ap2.getId().
                        JsonObjectBuilder job2Portal = Json.createObjectBuilder();
                        JsonObjectBuilder job2Toolkit = Json.createObjectBuilder();
                        job2Portal.add("uri", downloadPrefixProperty + ap2.getId() + "/"
                                + Download.downloadFilename(ap2, ""));
                        job2Toolkit.add("uri", uri.replaceFirst(sparqlPrefix, sesamePrefix));
                        ap2.setPortalData(job2Portal.build().toString());
                        ap2.setToolkitData(job2Toolkit.build().toString());
                        AccessPointUtils.updateAccessPoint(ap2);
                        jobPortal.add("source", AccessPoint.SYSTEM_SOURCE);
                    } else {
                        jobPortal.add("source", AccessPoint.USER_SOURCE);
                    }
                    ap.setPortalData(jobPortal.build().toString());
                    ap.setToolkitData(jobToolkit.build().toString());
                    AccessPointUtils.saveAccessPoint(ap);
                    break;
                case AccessPoint.WEBPAGE_TYPE:
                    uri = accessPoint.get("uri").asText();
                    if (uri.endsWith("concept/topConcepts")) {
                        ap.setType(AccessPoint.SISSVOC_TYPE);
                        jobPortal.add("source", AccessPoint.SYSTEM_SOURCE);
                        jobPortal.add("uri", uri.replaceFirst("/concept/topConcepts$", ""));
                    } else {
                        ap.setType(type);
                        jobPortal.add("uri", uri);
                    }
                    ap.setPortalData(jobPortal.build().toString());
                    ap.setToolkitData(jobToolkit.build().toString());
                    AccessPointUtils.saveAccessPoint(ap);
                    break;
                default:
                }
                System.out.println("type is: " + ap.getType());
                System.out.println("portal_data: " + ap.getPortalData());
                System.out.println("toolkit_data: " + ap.getToolkitData());
            }
        }
    }
}

From source file:MainServer.java

public static void main(String[] args) {
    int port = 1234;
    String filepath = "";
    String complete_path = "";
    String connection_type = "";
    String ip_address = "";
    int port_out = 0;
    int delay = 20; //20 by default

    //parse commands using getOpt (cli)
    //add Options
    Options options = new Options();

    options.addOption("p", true, "port_to_listen_on");
    options.addOption("d", true, "directory");
    options.addOption("T", false, "TCP mode");
    options.addOption("U", false, "UDP mode");
    options.addOption("s", true, "iPAddress");
    options.addOption("P", true, "port_to_connect_to");
    options.addOption("D", true, "delay");

    CommandLineParser clp = new DefaultParser();
    try {//from   w ww .j  av a 2s  .com
        CommandLine cl = clp.parse(options, args);

        //options for the server
        if (cl.hasOption("p")) {
            port = Integer.parseInt(cl.getOptionValue("p"));
        } else {
            System.err.println("No valid port selected.");
            return;
        }

        if (cl.hasOption("d")) {
            filepath = cl.getOptionValue("d");
            //if there a '/' in front, remove it to make it a valid directory
            if (filepath.substring(0, 1).equalsIgnoreCase("/")) {
                filepath = filepath.substring(1);
            }
        } else {
            System.err.println("No valid directory given.");
            return;
        }

        if (cl.hasOption("D")) {
            delay = Integer.parseInt(cl.getOptionValue("D"));
        }

        //options for the client
        if (cl.hasOption("T")) {
            connection_type = "T";
        } else if (cl.hasOption("U")) {
            connection_type = "U";
        }

        if (cl.hasOption("s")) {
            ip_address = cl.getOptionValue("s");
        }

        if (cl.hasOption("P")) {
            port_out = Integer.parseInt(cl.getOptionValue("P"));
        }

    } catch (ParseException e) {
        //TODO: handle exception
    }

    //create directory (if it doesn't already exist)
    try {
        Files.createDirectories(Paths.get(filepath));
    } catch (Exception e) {
        //TODO: handle exception
        System.err.println("Couldn't create directory");
        System.err.println(filepath);
    }

    //read in required files (create them if they dont already exist)
    try {
        Files.createFile(Paths.get(filepath + "/gossip.txt"));
        Files.createFile(Paths.get(filepath + "/peers.txt"));
    } catch (Exception e) {
        //TODO: handle exception
    }
    WriteToFiles.readFiles(filepath);

    //start the servers
    TCPServerSock tcpServer = new TCPServerSock(port, filepath, delay);
    UDPServer udpServer = new UDPServer(port, filepath);

    Thread tcpThread = new Thread(tcpServer);
    Thread udpThread = new Thread(udpServer);

    tcpThread.start();
    udpThread.start();

    //start the client
    if (!connection_type.equals("") && port_out != 0 && !ip_address.equals("")) {
        Client client = new Client(ip_address, port_out, connection_type);
        Thread clientThread = new Thread(client);
        clientThread.start();
    }

    //Start thread to forget peers
    ForgetPeer forgetPeer = new ForgetPeer(filepath + "/peers.txt", delay);
    Thread forgetPeerThread = new Thread(forgetPeer);
    forgetPeerThread.start();
}

From source file:OCRRestAPI.java

public static void main(String[] args) throws Exception {
    /*//w  ww  .  ja v  a 2  s .c om
              
         Sample project for OCRWebService.com (REST API).
         Extract text from scanned images and convert into editable formats.
         Please create new account with ocrwebservice.com via http://www.ocrwebservice.com/account/signup and get license code
            
     */

    // Provide your user name and license code
    String license_code = "88EF173D-CDEA-41B6-8D64-C04578ED8C4D";
    String user_name = "FERGOID";

    /*
            
      You should specify OCR settings. See full description http://www.ocrwebservice.com/service/restguide
             
      Input parameters:
             
     [language]      - Specifies the recognition language. 
                  This parameter can contain several language names separated with commas. 
                    For example "language=english,german,spanish".
               Optional parameter. By default:english
            
     [pagerange]     - Enter page numbers and/or page ranges separated by commas. 
               For example "pagerange=1,3,5-12" or "pagerange=allpages".
                    Optional parameter. By default:allpages
             
      [tobw]           - Convert image to black and white (recommend for color image and photo). 
               For example "tobw=false"
                    Optional parameter. By default:false
             
      [zone]          - Specifies the region on the image for zonal OCR. 
               The coordinates in pixels relative to the left top corner in the following format: top:left:height:width. 
               This parameter can contain several zones separated with commas. 
                 For example "zone=0:0:100:100,50:50:50:50"
                    Optional parameter.
              
      [outputformat]  - Specifies the output file format.
                    Can be specified up to two output formats, separated with commas.
               For example "outputformat=pdf,txt"
                    Optional parameter. By default:doc
            
      [gettext]      - Specifies that extracted text will be returned.
               For example "tobw=true"
                    Optional parameter. By default:false
            
       [description]  - Specifies your task description. Will be returned in response.
                    Optional parameter. 
            
            
     !!!!  For getting result you must specify "gettext" or "outputformat" !!!!  
            
    */

    // Build your OCR:

    // Extraction text with English language
    String ocrURL = "http://www.ocrwebservice.com/restservices/processDocument?gettext=true";

    // Extraction text with English and German language using zonal OCR
    ocrURL = "http://www.ocrwebservice.com/restservices/processDocument?language=english,german&zone=0:0:600:400,500:1000:150:400";

    // Convert first 5 pages of multipage document into doc and txt
    // ocrURL = "http://www.ocrwebservice.com/restservices/processDocument?language=english&pagerange=1-5&outputformat=doc,txt";

    // Full path to uploaded document
    String filePath = "sarah-morgan.jpg";

    byte[] fileContent = Files.readAllBytes(Paths.get(filePath));

    URL url = new URL(ocrURL);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestMethod("POST");

    connection.setRequestProperty("Authorization",
            "Basic " + Base64.getEncoder().encodeToString((user_name + ":" + license_code).getBytes()));

    // Specify Response format to JSON or XML (application/json or application/xml)
    connection.setRequestProperty("Content-Type", "application/json");

    connection.setRequestProperty("Content-Length", Integer.toString(fileContent.length));

    int httpCode;
    try (OutputStream stream = connection.getOutputStream()) {

        // Send POST request
        stream.write(fileContent);
        stream.close();
    } catch (Exception e) {
        System.out.println(e.toString());
    }

    httpCode = connection.getResponseCode();

    System.out.println("HTTP Response code: " + httpCode);

    // Success request
    if (httpCode == HttpURLConnection.HTTP_OK) {
        // Get response stream
        String jsonResponse = GetResponseToString(connection.getInputStream());

        // Parse and print response from OCR server
        PrintOCRResponse(jsonResponse);
    } else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        System.out.println("OCR Error Message: Unauthorizied request");
    } else {
        // Error occurred
        String jsonResponse = GetResponseToString(connection.getErrorStream());

        JSONParser parser = new JSONParser();
        JSONObject jsonObj = (JSONObject) parser.parse(jsonResponse);

        // Error message
        System.out.println("Error Message: " + jsonObj.get("ErrorMessage"));
    }

    connection.disconnect();

}

From source file:com.curecomp.primefaces.migrator.PrimefacesMigration.java

public static void main(String[] args) throws Exception {
    // Let's use some colors :)
    //        AnsiConsole.systemInstall();
    CommandLineParser cliParser = new BasicParser();
    CommandLine cli = null;/*from ww  w  .  ja  va  2  s . c o m*/
    try {
        cli = cliParser.parse(OPTIONS, args);
    } catch (ParseException e) {
        printHelp();
    }
    if (!cli.hasOption("s")) {
        printHelp();
    }

    String sourcePattern;
    if (cli.hasOption("p")) {
        sourcePattern = cli.getOptionValue("p");
    } else {
        sourcePattern = DEFAULT_SOURCE_PATTERN;
    }

    String defaultAnswer;
    if (cli.hasOption("default-answer")) {
        defaultAnswer = cli.getOptionValue("default-answer");
    } else {
        defaultAnswer = DEFAULT_DEFAULT_PROMPT_ANSWER;
    }

    boolean defaultAnswerYes = defaultAnswer.equalsIgnoreCase("y");
    boolean quiet = cli.hasOption("q");
    boolean testWrite = cli.hasOption("t");
    Path sourceDirectory = Paths.get(cli.getOptionValue("s")).toAbsolutePath();
    // Since we use IO we will have some blocking threads hanging around
    int threadCount = Runtime.getRuntime().availableProcessors() * 2;
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>());
    BlockingQueue<WidgetVarLocation> foundUsages = new LinkedBlockingQueue<>();
    BlockingQueue<WidgetVarLocation> unusedOrAmbiguous = new LinkedBlockingQueue<>();
    BlockingQueue<WidgetVarLocation> skippedUsages = new LinkedBlockingQueue<>();
    List<Future<?>> futures = new ArrayList<>();

    findWidgetVars(sourceDirectory, sourcePattern, threadPool).forEach(widgetVarLocation -> {
        // We can't really find usages of widget vars that use EL expressions :(
        if (widgetVarLocation.widgetVar.contains("#")) {
            unusedOrAmbiguous.add(widgetVarLocation);
            return;
        }

        try {
            FileActionVisitor visitor = new FileActionVisitor(sourceDirectory, sourcePattern,
                    sourceFile -> futures.add(threadPool.submit((Callable<?>) () -> {
                        findWidgetVarUsages(sourceFile, widgetVarLocation, foundUsages, skippedUsages,
                                unusedOrAmbiguous);
                        return null;
                    })));

            Files.walkFileTree(sourceDirectory, visitor);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    });

    awaitAll(futures);

    new TreeSet<>(skippedUsages).forEach(widgetUsage -> {
        int startIndex = widgetUsage.columnNr;
        int endIndex = startIndex + widgetUsage.widgetVar.length();
        String relativePath = widgetUsage.location.toAbsolutePath().toString()
                .substring(sourceDirectory.toString().length());
        String previous = replace(widgetUsage.line, startIndex, endIndex,
                Ansi.ansi().bold().fg(Ansi.Color.RED).a(widgetUsage.widgetVar).reset().toString());
        System.out.println("Skipped " + relativePath + " at line " + widgetUsage.lineNr + " and col "
                + widgetUsage.columnNr + " for widgetVar '" + widgetUsage.widgetVar + "'");
        System.out.println("\t" + previous);
    });

    Map<WidgetVarLocation, List<WidgetVarLocation>> written = new HashMap<>();

    new TreeSet<>(foundUsages).forEach(widgetUsage -> {
        WidgetVarLocation key = new WidgetVarLocation(null, widgetUsage.location, widgetUsage.lineNr, -1, null);
        List<WidgetVarLocation> writtenList = written.get(key);
        int existing = writtenList == null ? 0 : writtenList.size();
        int startIndex = widgetUsage.columnNr;
        int endIndex = startIndex + widgetUsage.widgetVar.length();
        String relativePath = widgetUsage.location.toAbsolutePath().toString()
                .substring(sourceDirectory.toString().length());
        String next = replace(widgetUsage.line, startIndex, endIndex, Ansi.ansi().bold().fg(Ansi.Color.RED)
                .a("PF('" + widgetUsage.widgetVar + "')").reset().toString());
        System.out
                .println(relativePath + " at line " + widgetUsage.lineNr + " and col " + widgetUsage.columnNr);
        System.out.println("\t" + next);
        System.out.print("Replace (Y/N)? [" + (defaultAnswerYes ? "Y" : "N") + "]: ");

        String input;

        if (quiet) {
            input = "";
            System.out.println();
        } else {
            try {
                do {
                    input = in.readLine();
                } while (input != null && !input.isEmpty() && !"y".equalsIgnoreCase(input)
                        && !"n".equalsIgnoreCase(input));
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }

        if (input == null) {
            System.out.println("Aborted!");
        } else if (input.isEmpty() && defaultAnswerYes || !input.isEmpty() && !"n".equalsIgnoreCase(input)) {
            System.out.println("Replaced!");
            System.out.print("\t");
            if (writtenList == null) {
                writtenList = new ArrayList<>();
                written.put(key, writtenList);
            }

            writtenList.add(widgetUsage);
            List<String> lines;
            try {
                lines = Files.readAllLines(widgetUsage.location);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }

            try (OutputStream os = testWrite ? new ByteArrayOutputStream()
                    : Files.newOutputStream(widgetUsage.location);
                    PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8))) {
                String line;

                for (int i = 0; i < lines.size(); i++) {
                    int lineNr = i + 1;
                    line = lines.get(i);

                    if (lineNr == widgetUsage.lineNr) {
                        int begin = widgetUsage.columnNr + (testWrite ? 0 : existing * 6);
                        int end = begin + widgetUsage.widgetVar.length();
                        String newLine = replace(line, begin, end, "PF('" + widgetUsage.widgetVar + "')",
                                false);

                        if (testWrite) {
                            System.out.println(newLine);
                        } else {
                            pw.println(newLine);
                        }
                    } else {
                        if (!testWrite) {
                            pw.println(line);
                        }
                    }
                }
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        } else {
            System.out.println("Skipped!");
        }
    });

    new TreeSet<>(unusedOrAmbiguous).forEach(widgetUsage -> {
        int startIndex = widgetUsage.columnNr;
        int endIndex = startIndex + widgetUsage.widgetVar.length();
        String relativePath = widgetUsage.location.toAbsolutePath().toString()
                .substring(sourceDirectory.toString().length());
        String previous = replace(widgetUsage.line, startIndex, endIndex,
                Ansi.ansi().bold().fg(Ansi.Color.RED).a(widgetUsage.widgetVar).reset().toString());
        System.out.println("Skipped unused or ambiguous " + relativePath + " at line " + widgetUsage.lineNr
                + " and col " + widgetUsage.columnNr);
        System.out.println("\t" + previous);
    });

    threadPool.shutdown();
}

From source file:es.upm.oeg.tools.quality.ldsniffer.cmd.LDSnifferApp.java

public static void main(String[] args) {

    HelpFormatter help = new HelpFormatter();
    String header = "Assess a list of Linked Data resources using Linked Data Quality Model.";
    String footer = "Please report issues at https://github.com/nandana/ld-sniffer";

    try {// w  w  w .  j av  a 2s  . co  m
        CommandLine line = parseArguments(args);
        if (line.hasOption("help")) {
            help.printHelp("LDSnifferApp", header, OPTIONS, footer, true);
            System.exit(0);
        }

        evaluationTimeout = Integer.parseInt(line.getOptionValue("t", "10"));

        if (line.hasOption("md")) {
            includeMetricDefinitions = true;
        }
        if (line.hasOption("rdf")) {
            rdfOutput = true;
        }

        logger.info("URL List: " + line.getOptionValue("ul"));
        logger.info("TDB Path: " + line.getOptionValue("tdb"));
        logger.info("Metrics Path: " + line.getOptionValue("ml"));
        logger.info("Include Metric definitions: " + line.getOptionValue("ml"));
        logger.info("RDF output: " + line.getOptionValue("rdf"));
        logger.info("Timeout (mins): " + evaluationTimeout);

        if (line.hasOption("ml")) {
            Path path = Paths.get(line.getOptionValue("ml"));
            if (!Files.exists(path)) {
                throw new IOException(path.toAbsolutePath().toString() + " : File doesn't exit.");
            }
        }

        //Set the TDB path
        String tdbDirectory;
        if (line.hasOption("tdb")) {
            tdbDirectory = line.getOptionValue("tdb");
        } else {
            Path tempPath = Files.createTempDirectory("tdb_");
            tdbDirectory = tempPath.toAbsolutePath().toString();
        }

        // Create the URL list for the evaluation
        if (!line.hasOption("ul") && !line.hasOption("url")) {
            System.out.println("One of the following parameters are required: url or urlList ");
            help.printHelp("LDSnifferApp", header, OPTIONS, footer, true);
            System.exit(0);
        } else if (line.hasOption("ul") && line.hasOption("url")) {
            System.out.println("You have to specify either url or urlList, not both.");
            help.printHelp("LDSnifferApp", header, OPTIONS, footer, true);
            System.exit(0);
        }

        List<String> urlList = null;
        if (line.hasOption("ul")) {
            Path path = Paths.get(line.getOptionValue("ul"));
            logger.info("Path : " + path.toAbsolutePath().toString());
            logger.info("Path exits : " + Files.exists(path));
            urlList = Files.readAllLines(path, Charset.defaultCharset());
        } else if (line.hasOption("url")) {
            urlList = new ArrayList<>();
            urlList.add(line.getOptionValue("url"));
        }

        Executor executor = new Executor(tdbDirectory, urlList);
        executor.execute();

    } catch (MissingOptionException e) {
        help.printHelp("LDSnifferApp", header, OPTIONS, footer, true);
        logger.error("Missing arguments.  Reason: " + e.getMessage(), e);
        System.exit(1);
    } catch (ParseException e) {
        logger.error("Parsing failed.  Reason: " + e.getMessage(), e);
        System.exit(1);
    } catch (IOException e) {
        logger.error("Execution failed.  Reason: " + e.getMessage(), e);
        System.exit(1);
    }

}

From source file:edu.mit.lib.tools.Modernize.java

public static void main(String[] args) throws Exception {

    // create an options object and populate it
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    options.addOption("i", "identifier", true, "root handle to migrate - 'all' for entire repo");
    options.addOption("t", "target", true, "URL of mds repository to import into");
    options.addOption("s", "scratch", true, "scratch directory for processing");
    options.addOption("m", "migrate", false,
            "export for migration (remove handle and metadata that will be re-created in new system)");
    options.addOption("h", "help", false, "help");

    CommandLine line = parser.parse(options, args);

    if (line.hasOption('h')) {
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("Modernize\n", options);
        System.out.println(/* w w w  .  j a v a 2  s. c  o  m*/
                "\nentire repository: Modernize -i all -t http://my-mds-repo.org/webapi -s /dspace/export");
        System.out.println(
                "\ncontent subtree: Modernize -i 123456789/1 -t http://my-mds-repo.org/webapi -s /dspace/export");
        System.exit(0);
    }

    String scratch = null;
    if (line.hasOption('s')) {
        scratch = line.getOptionValue('s');
        if (scratch == null) {
            System.out.println("Scratch directory required!");
            System.exit(1);
        }
    }

    Modernize mod = new Modernize(Paths.get(scratch));

    if (line.hasOption('i')) {
        String id = line.getOptionValue('i');
        if (id != null) {
            mod.exportIdentifier(id);
        } else {
            mod.bail("Must provide an identifer!");
        }
    }

    if (line.hasOption('t')) {
        String targetUrl = line.getOptionValue('t');
        if (targetUrl != null) {
            mod.importToMds(targetUrl);
        } else {
            mod.bail("Must provide an URL to an mds repository!");
        }
    }

    mod.finish();
}

From source file:edu.ehu.galan.lite.Example.java

public static void main(String[] args) {
    //initizalize ehcache system
    System.setProperty("net.sf.ehcache.enableShutdownHook", "true");
    if (CacheManager.getCacheManager("ehcacheLitet.xml") == null) {
        CacheManager.create("ehcacheLitet.xml");
    }//from w  ww.  jav  a  2 s .c  o m
    cache = CacheManager.getInstance().getCache("LiteCache");
    //load the corpus to process
    Corpus corpus = new Corpus("en");
    //we spedify the directory and the database mapping (wikipedia in this case)
    corpus.loadCorpus("testCorpus", Document.SourceType.wikipedia);
    //will read the document using Illinois NLP utilities
    PlainTextDocumentReaderLBJEn parser = new PlainTextDocumentReaderLBJEn();
    AlgorithmRunner runner = new AlgorithmRunner();
    String resources = System.getProperty("user.dir") + "/resources/";
    //algorithms initializacion
    CValueAlgortithm cvalue = new CValueAlgortithm();
    cvalue.addNewProcessingFilter(new AdjPrepNounFilter());
    TFIDFAlgorithm tf = new TFIDFAlgorithm(new CaseStemmer(CaseStemmer.CaseType.lowercase), "en");
    ShallowParsingGrammarAlgortithm sha = new ShallowParsingGrammarAlgortithm(
            System.getProperty("user.dir") + "/resources/lite/" + "grammars/Cg2EnGrammar.grammar", "cg3/");
    KPMinerAlgorithm kp = new KPMinerAlgorithm();
    RakeAlgorithm ex = new RakeAlgorithm();
    ex.loadStopWordsList("resources/lite/stopWordLists/RakeStopLists/SmartStopListEn");
    ex.loadPunctStopWord("resources/lite/stopWordLists/RakeStopLists/RakePunctDefaultStopList");
    //algorithm submitting to execute them in parallel
    runner.submitAlgorithm(kp);
    runner.submitAlgorithm(cvalue);
    runner.submitAlgorithm(tf);
    runner.submitAlgorithm(ex);
    runner.submitAlgorithm(sha);
    //load stop list
    List<String> standardStop = null;
    try {
        standardStop = Files.readAllLines(Paths.get(resources + "lite/stopWordLists/standardStopList"),
                StandardCharsets.UTF_8);

    } catch (IOException e1x) {
        Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, e1x);
    }
    //initialize Wikiminer helper (class that interacts with Wikiminer services)
    WikiminnerHelper helper = WikiminnerHelper.getInstance(resources);
    helper.setLanguage("en");
    //we may operate in local mode (using Wikiminer as API instead of interacting via REST api
    // helper.setLocalMode(false,"/home/angel/nfs/wikiminer/configs/wikipedia");
    WikiMinerMap wikimapping = new WikiMinerMap(resources, helper);
    CValueWikiDisambiguator disambiguator = new CValueWikiDisambiguator(resources, helper);
    CValueWikiRelationship relate = new CValueWikiRelationship(resources, helper);
    WikipediaData data = new WikipediaData(resources, helper);
    helper.openConnection();
    //process all the documents in the corpus
    while (!corpus.getDocQueue().isEmpty()) {
        Document doc = corpus.getDocQueue().poll();
        doc.setSource(Document.SourceType.wikipedia);
        parser.readSource(doc.getPath());
        doc.setSentenceList(parser.getSentenceList());
        doc.setTokenList(parser.getTokenizedSentenceList());
        System.out.println(doc.getName());
        runner.runAlgorihms(doc, resources);
        doc.applyGlobalStopWordList(standardStop);
        doc.mapThreshold(1.9f, new String[] { "CValue" });
        doc.mapThreshold(0.00034554f, new String[] { "TFIDF" });
        doc.removeAndMixTerms();
        //map document
        wikimapping.mapCorpus(doc);
        disambiguator.disambiguateTopics(doc);
        //we may disambiguate topics that do not disambiguated correctly
        DuplicateRemoval.disambiguationRemoval(doc);
        DuplicateRemoval.topicDuplicateRemoval(doc);
        //obtain the wiki links,labels, etc
        data.processDocument(doc);
        //measure domain relatedness
        relate.relate(doc);
        //save the results
        Document.saveJsonToDir("", doc);
    }
    //close wikiminer connection and caches
    helper.closeConnection();
    cache.dispose();
    CacheManager.getInstance().shutdown();
    System.exit(0);
}

From source file:fi.helsinki.cs.iot.kahvihub.KahviHub.java

public static void main(String[] args) throws InterruptedException {
    // create Options object
    Options options = new Options();
    // add conf file option
    options.addOption("c", true, "config file");
    CommandLineParser parser = new BasicParser();
    CommandLine cmd;// ww w.j  ava2  s  . c  o m
    try {
        cmd = parser.parse(options, args);
        String configFile = cmd.getOptionValue("c");
        if (configFile == null) {
            Log.e(TAG, "The config file option was not provided");
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("d", options);
            System.exit(-1);
        } else {
            try {
                HubConfig hubConfig = ConfigurationFileParser.parseConfigurationFile(configFile);
                Path libdir = Paths.get(hubConfig.getLibdir());
                if (hubConfig.isDebugMode()) {
                    File dir = libdir.toFile();
                    if (dir.exists() && dir.isDirectory())
                        for (File file : dir.listFiles())
                            file.delete();
                }
                final IotHubHTTPD server = new IotHubHTTPD(hubConfig.getPort(), libdir, hubConfig.getHost());
                init(hubConfig);
                try {
                    server.start();
                } catch (IOException ioe) {
                    Log.e(TAG, "Couldn't start server:\n" + ioe);
                    System.exit(-1);
                }
                Runtime.getRuntime().addShutdownHook(new Thread() {
                    @Override
                    public void run() {
                        server.stop();
                        Log.i(TAG, "Server stopped");
                    }
                });

                while (true) {
                    Thread.sleep(1000);
                }
            } catch (ConfigurationParsingException | IOException e) {
                System.out.println("1:" + e.getMessage());
                Log.e(TAG, e.getMessage());
                System.exit(-1);
            }
        }

    } catch (ParseException e) {
        System.out.println(e.getMessage());
        Log.e(TAG, e.getMessage());
        System.exit(-1);
    }
}

From source file:eu.itesla_project.offline.mpi.Master.java

public static void main(String[] args) throws Exception {
    try {//w  ww  .j a v a  2s .com
        CommandLineParser parser = new GnuParser();
        CommandLine line = parser.parse(OPTIONS, args);

        Mode mode = Mode.valueOf(line.getOptionValue("mode"));
        String simulationDbName = line.hasOption("simulation-db-name")
                ? line.getOptionValue("simulation-db-name")
                : OfflineConfig.DEFAULT_SIMULATION_DB_NAME;
        String rulesDbName = line.hasOption("rules-db-name") ? line.getOptionValue("rules-db-name")
                : OfflineConfig.DEFAULT_RULES_DB_NAME;
        String metricsDbName = line.hasOption("metrics-db-name") ? line.getOptionValue("metrics-db-name")
                : OfflineConfig.DEFAULT_METRICS_DB_NAME;
        Path tmpDir = Paths.get(line.getOptionValue("tmp-dir"));
        Class<?> statisticsFactoryClass = Class.forName(line.getOptionValue("statistics-factory-class"));
        Path statisticsDbDir = Paths.get(line.getOptionValue("statistics-db-dir"));
        String statisticsDbName = line.getOptionValue("statistics-db-name");
        int coresPerRank = Integer.parseInt(line.getOptionValue("cores"));
        Path stdOutArchive = line.hasOption("stdout-archive") ? Paths.get(line.getOptionValue("stdout-archive"))
                : null;
        String workflowId = line.hasOption("workflow") ? line.getOptionValue("workflow") : null;

        MpiExecutorContext mpiExecutorContext = new MultiStateNetworkAwareMpiExecutorContext();
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        ExecutorService offlineExecutorService = MultiStateNetworkAwareExecutors
                .newSizeLimitedThreadPool("OFFLINE_POOL", 100);
        try {
            MpiStatisticsFactory statisticsFactory = statisticsFactoryClass
                    .asSubclass(MpiStatisticsFactory.class).newInstance();
            try (MpiStatistics statistics = statisticsFactory.create(statisticsDbDir, statisticsDbName)) {
                try (ComputationManager computationManager = new MpiComputationManager(tmpDir, statistics,
                        mpiExecutorContext, coresPerRank, false, stdOutArchive)) {
                    OfflineConfig config = OfflineConfig.load();
                    try (LocalOfflineApplication application = new LocalOfflineApplication(config,
                            computationManager, simulationDbName, rulesDbName, metricsDbName,
                            scheduledExecutorService, offlineExecutorService)) {
                        switch (mode) {
                        case ui:
                            application.await();
                            break;

                        case simulations: {
                            if (workflowId == null) {
                                workflowId = application.createWorkflow(null,
                                        OfflineWorkflowCreationParameters.load());
                            }
                            application.startWorkflowAndWait(workflowId, OfflineWorkflowStartParameters.load());
                        }
                            break;

                        case rules: {
                            if (workflowId == null) {
                                throw new RuntimeException("Workflow '" + workflowId + "' not found");
                            }
                            application.computeSecurityRulesAndWait(workflowId);
                        }
                            break;

                        default:
                            throw new IllegalArgumentException("Invalid mode " + mode);
                        }
                    }
                }
            }
        } finally {
            mpiExecutorContext.shutdown();
            offlineExecutorService.shutdown();
            scheduledExecutorService.shutdown();
            offlineExecutorService.awaitTermination(15, TimeUnit.MINUTES);
            scheduledExecutorService.awaitTermination(15, TimeUnit.MINUTES);
        }
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("master", OPTIONS, true);
        System.exit(-1);
    } catch (Throwable t) {
        LOGGER.error(t.toString(), t);
        System.exit(-1);
    }
}

From source file:de.huberlin.wbi.cuneiform.cmdline.main.Main.java

public static void main(String[] args)
        throws IOException, ParseException, InterruptedException, NotDerivableException {

    CommandLine cmd;/*from   ww w.  j ava  2 s  . co  m*/
    Options opt;
    BaseRepl repl;
    BaseCreActor cre;
    Path sandbox;
    ExecutorService executor;
    TicketSrcActor ticketSrc;
    JsonSummary summary;
    Path summaryPath;
    Log statLog;
    int nthread;
    Path workDir;

    statLog = LogFactory.getLog("statLogger");

    executor = Executors.newCachedThreadPool();
    try {

        opt = getOptions();
        cmd = parse(args, opt);
        config(cmd);

        if (cmd.hasOption('h')) {

            System.out.println("CUNEIFORM - A Functional Workflow Language\nversion " + BaseRepl.LABEL_VERSION
                    + " build " + BaseRepl.LABEL_BUILD);
            new HelpFormatter().printHelp("java -jar cuneiform.jar [OPTION]*", opt);

            return;
        }

        if (cmd.hasOption('r'))
            Invocation.putLibPath(ForeignLambdaExpr.LANGID_R, cmd.getOptionValue('r'));

        if (cmd.hasOption('y'))
            Invocation.putLibPath(ForeignLambdaExpr.LANGID_PYTHON, cmd.getOptionValue('y'));

        if (cmd.hasOption('l'))
            sandbox = Paths.get(cmd.getOptionValue("l"));
        else
            sandbox = Paths.get(System.getProperty("user.home")).resolve(".cuneiform");

        sandbox = sandbox.toAbsolutePath();

        if (cmd.hasOption('c'))
            LocalThread.deleteIfExists(sandbox);

        if (cmd.hasOption('t'))
            nthread = Integer.valueOf(cmd.getOptionValue('t'));
        else
            nthread = Runtime.getRuntime().availableProcessors();

        if (cmd.hasOption('w'))
            workDir = Paths.get(cmd.getOptionValue('w'));
        else
            workDir = Paths.get(System.getProperty("user.dir"));

        workDir = workDir.toAbsolutePath();

        switch (platform) {

        case PLATFORM_LOCAL:

            if (!Files.exists(sandbox))
                Files.createDirectories(sandbox);

            cre = new LocalCreActor(sandbox, workDir, nthread);
            break;

        case PLATFORM_HTCONDOR:

            if (!Files.exists(sandbox))
                Files.createDirectories(sandbox);

            if (cmd.hasOption('m')) { // MAX_TRANSFER SIZE
                String maxTransferSize = cmd.getOptionValue('m');
                try {
                    cre = new CondorCreActor(sandbox, maxTransferSize);
                } catch (Exception e) {
                    System.out.println("INVALID '-m' option value: " + maxTransferSize
                            + "\n\nCUNEIFORM - A Functional Workflow Language\nversion "
                            + BaseRepl.LABEL_VERSION + " build " + BaseRepl.LABEL_BUILD);
                    new HelpFormatter().printHelp("java -jar cuneiform.jar [OPTION]*", opt);

                    return;
                }
            } else {
                cre = new CondorCreActor(sandbox);
            }

            break;

        default:
            throw new RuntimeException("Platform not recognized.");
        }

        executor.submit(cre);
        ticketSrc = new TicketSrcActor(cre);
        executor.submit(ticketSrc);
        executor.shutdown();

        switch (format) {

        case FORMAT_CF:

            if (cmd.hasOption("i"))
                repl = new InteractiveRepl(ticketSrc, statLog);
            else
                repl = new CmdlineRepl(ticketSrc, statLog);
            break;

        case FORMAT_DAX:
            repl = new DaxRepl(ticketSrc, statLog);
            break;

        default:
            throw new RuntimeException("Format not recognized.");
        }

        if (cmd.hasOption("i")) {

            // run in interactive mode
            BaseRepl.run(repl);

            return;
        }

        // run in quiet mode

        if (inputFileVector.length > 0)

            for (Path f : inputFileVector)
                repl.interpret(readFile(f));

        else
            repl.interpret(readStdIn());

        Thread.sleep(3 * Actor.DELAY);
        while (repl.isBusy())
            Thread.sleep(Actor.DELAY);

        if (cmd.hasOption("s")) {

            summary = new JsonSummary(ticketSrc.getRunId(), sandbox, repl.getAns());
            summaryPath = Paths.get(cmd.getOptionValue("s"));
            summaryPath = summaryPath.toAbsolutePath();
            try (BufferedWriter writer = Files.newBufferedWriter(summaryPath, Charset.forName("UTF-8"))) {

                writer.write(summary.toString());
            }

        }

    } finally {
        executor.shutdownNow();
    }

}