当前位置: 首页>>代码示例>>Java>>正文


Java CommandLine.hasOption方法代码示例

本文整理汇总了Java中eu.fbk.utils.core.CommandLine.hasOption方法的典型用法代码示例。如果您正苦于以下问题:Java CommandLine.hasOption方法的具体用法?Java CommandLine.hasOption怎么用?Java CommandLine.hasOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eu.fbk.utils.core.CommandLine的用法示例。


在下文中一共展示了CommandLine.hasOption方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    BuildUserIndex extractor = new BuildUserIndex();

    try {
        // Parse command line
        final CommandLine cmd = provideParameterList().parse(args);

        // Extract tweets path
        if (!cmd.hasOption(TWEETS_PATH)) {
            throw new Exception("Insufficient configuration");
        }
        //noinspection ConstantConditions
        final Path tweetsPath = new Path(cmd.getOptionValue(TWEETS_PATH, String.class));

        if (cmd.hasOption(RESULTS_PATH)) {
            //noinspection ConstantConditions
            final Path results = new Path(cmd.getOptionValue(RESULTS_PATH, String.class));
            extractor.start(tweetsPath, results);
            return;
        }

        // Extract connection if necessary
        if (!cmd.hasOption(DB_CONNECTION)
                || !cmd.hasOption(DB_USER)
                || !cmd.hasOption(DB_PASSWORD)) {
            throw new Exception("Insufficient configuration");
        }

        final Configuration parameters = new Configuration();
        parameters.setString("db.connection", cmd.getOptionValue(DB_CONNECTION, String.class));
        parameters.setString("db.user", cmd.getOptionValue(DB_USER, String.class));
        parameters.setString("db.password", cmd.getOptionValue(DB_PASSWORD, String.class));

        extractor.start(tweetsPath, parameters);
    } catch (final Throwable ex) {
        // Handle exception
        CommandLine.fail(ex);
    }
}
 
开发者ID:Remper,项目名称:sociallink,代码行数:40,代码来源:BuildUserIndex.java

示例2: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(final String[] args) {
    try {
        // Parse command line
        final CommandLine cmd = CommandLine.parser().withName("eval-evaluate")
                .withOption("s", "simplified", "use simplified gold standard")
                .withHeader("Evaluates precision/recall given aligned data.").parse(args);

        // Extract options
        final List<String> inputFiles = cmd.getArgs(String.class);
        final boolean simplified = cmd.hasOption("s");

        // Read the input
        final Map<String, String> namespaces = Maps.newHashMap();
        final List<Statement> stmts = Lists.newArrayList();
        RDFSources.read(false, false, null, null,
                inputFiles.toArray(new String[inputFiles.size()])).emit(
                RDFHandlers.wrap(stmts, namespaces), 1);

        // Perform the evaluation
        final Evaluation evaluation = Evaluation.evaluate(stmts, simplified);
        LOGGER.info("Evaluation results:\n\n{}", evaluation.getReport());

    } catch (final Throwable ex) {
        // Display error information and terminate
        CommandLine.fail(ex);
    }
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:28,代码来源:Evaluation.java

示例3: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            final CommandLine cmd = CommandLine
                    .parser()
                    .withName("fr94-extractor")
                    .withHeader("Extract FR94 documents from TREC dataset and save them in NAF format")
                    .withOption("i", "input", "Input folder", "FOLDER", CommandLine.Type.DIRECTORY_EXISTING, true,
                            false, true)
                    .withOption("o", "output", "Output folder", "FOLDER", CommandLine.Type.DIRECTORY, true, false, true)
                    .withOption("u", "url-template", "URL template (with %d for the ID)", "URL",
                            CommandLine.Type.STRING, true, false, false)
                    .withLogger(LoggerFactory.getLogger("eu.fbk")) //
                    .parse(args);

            File inputDir = cmd.getOptionValue("input", File.class);

            String urlTemplate = DEFAULT_URL;
            if (cmd.hasOption("url-template")) {
                urlTemplate = cmd.getOptionValue("url-template", String.class);
            }

            File outputDir = cmd.getOptionValue("output", File.class);
            if (!outputDir.exists()) {
                outputDir.mkdirs();
            }

            for (final File file : Files.fileTreeTraverser().preOrderTraversal(inputDir)) {
                if (!file.isFile()) {
                    continue;
                }
                if (file.getName().startsWith(".")) {
                    continue;
                }

                String outputTemplate = outputDir.getAbsolutePath() + File.separator + file.getName();
                File newFolder = new File(outputTemplate);
                newFolder.mkdirs();

                outputTemplate += File.separator + "NAF";
                saveFile(file, outputTemplate, urlTemplate);
            }
        } catch (Exception e) {
            CommandLine.fail(e);
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:48,代码来源:FR94.java

示例4: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            final CommandLine cmd = CommandLine
                    .parser()
                    .withName("latimes-extractor")
                    .withHeader("Extract LATIMES documents from TREC dataset and save them in NAF format")
                    .withOption("i", "input", "Input folder", "FOLDER", CommandLine.Type.DIRECTORY_EXISTING, true,
                            false, true)
                    .withOption("o", "output", "Output folder", "FOLDER", CommandLine.Type.DIRECTORY, true, false, true)
                    .withOption("u", "url-template", "URL template (with %d for the ID)", "URL",
                            CommandLine.Type.STRING, true, false, false)
                    .withLogger(LoggerFactory.getLogger("eu.fbk")) //
                    .parse(args);

            File inputDir = cmd.getOptionValue("input", File.class);

            String urlTemplate = DEFAULT_URL;
            if (cmd.hasOption("url-template")) {
                urlTemplate = cmd.getOptionValue("url-template", String.class);
            }

            File outputDir = cmd.getOptionValue("output", File.class);
            if (!outputDir.exists()) {
                outputDir.mkdirs();
            }

            for (final File file : Files.fileTreeTraverser().preOrderTraversal(inputDir)) {
                if (!file.isFile()) {
                    continue;
                }
                if (file.getName().startsWith(".")) {
                    continue;
                }

                String outputTemplate = outputDir.getAbsolutePath() + File.separator + file.getName();
                File newFolder = new File(outputTemplate);
                newFolder.mkdirs();

                outputTemplate += File.separator + "NAF";
                saveFile(file, outputTemplate, urlTemplate);
            }
        } catch (Exception e) {
            CommandLine.fail(e);
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:48,代码来源:LATIMES.java

示例5: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            final CommandLine cmd = CommandLine
                    .parser()
                    .withName("cr-extractor")
                    .withHeader("Extract CR documents from TREC dataset and save them in NAF format")
                    .withOption("i", "input", "Input folder", "FOLDER", CommandLine.Type.DIRECTORY_EXISTING, true,
                            false, true)
                    .withOption("o", "output", "Output folder", "FOLDER", CommandLine.Type.DIRECTORY, true, false, true)
                    .withOption("u", "url-template", "URL template (with %d for the ID)", "URL",
                            CommandLine.Type.STRING, true, false, false)
                    .withLogger(LoggerFactory.getLogger("eu.fbk")) //
                    .parse(args);

            File inputDir = cmd.getOptionValue("input", File.class);

            String urlTemplate = DEFAULT_URL;
            if (cmd.hasOption("url-template")) {
                urlTemplate = cmd.getOptionValue("url-template", String.class);
            }

            File outputDir = cmd.getOptionValue("output", File.class);
            if (!outputDir.exists()) {
                outputDir.mkdirs();
            }

            for (final File file : Files.fileTreeTraverser().preOrderTraversal(inputDir)) {
                if (!file.isFile()) {
                    continue;
                }
                if (file.getName().startsWith(".")) {
                    continue;
                }

                String outputTemplate = outputDir.getAbsolutePath() + File.separator + file.getName();
                File newFolder = new File(outputTemplate);
                newFolder.mkdirs();

                outputTemplate += File.separator + "NAF";
                saveFile(file, outputTemplate, urlTemplate);
            }
        } catch (Exception e) {
            CommandLine.fail(e);
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:48,代码来源:CR.java

示例6: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            final CommandLine cmd = CommandLine
                    .parser()
                    .withName("ft-extractor")
                    .withHeader("Extract FT documents from TREC dataset and save them in NAF format")
                    .withOption("i", "input", "Input folder", "FOLDER", CommandLine.Type.DIRECTORY_EXISTING, true,
                            false, true)
                    .withOption("o", "output", "Output folder", "FOLDER", CommandLine.Type.DIRECTORY, true, false, true)
                    .withOption("u", "url-template", "URL template (with %d for the ID)", "URL",
                            CommandLine.Type.STRING, true, false, false)
                    .withLogger(LoggerFactory.getLogger("eu.fbk")) //
                    .parse(args);

            File inputDir = cmd.getOptionValue("input", File.class);

            String urlTemplate = DEFAULT_URL;
            if (cmd.hasOption("url-template")) {
                urlTemplate = cmd.getOptionValue("url-template", String.class);
            }

            File outputDir = cmd.getOptionValue("output", File.class);
            if (!outputDir.exists()) {
                outputDir.mkdirs();
            }

            for (final File file : Files.fileTreeTraverser().preOrderTraversal(inputDir)) {
                if (!file.isFile()) {
                    continue;
                }

                String outputTemplate = outputDir.getAbsolutePath() + File.separator + file.getName();
                File newFolder = new File(outputTemplate);
                newFolder.mkdirs();

                outputTemplate += File.separator + "NAF";
                saveFile(file, outputTemplate, urlTemplate);
            }
        } catch (Exception e) {
            CommandLine.fail(e);
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:45,代码来源:FT.java

示例7: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            final CommandLine cmd = CommandLine
                    .parser()
                    .withName("queries-extractor")
                    .withHeader("Extract Queries documents from TREC dataset and save them in NAF format")
                    .withOption("i", "input", "Input file", "FILE", CommandLine.Type.FILE, true,
                            false, true)
                    .withOption("o", "output", "Output folder", "FOLDER", CommandLine.Type.DIRECTORY, true, false, true)
                    .withOption("u", "url-template", "URL template (with %d for the ID)", "URL",
                            CommandLine.Type.STRING, true, false, false)
                    .withLogger(LoggerFactory.getLogger("eu.fbk")) //
                    .parse(args);

            File inputfile = cmd.getOptionValue("input", File.class);
            File outputFolder = cmd.getOptionValue("output", File.class);

            String urlTemplate = DEFAULT_URL;
            if (cmd.hasOption("url-template")) {
                urlTemplate = cmd.getOptionValue("url-template", String.class);
            }

            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

            LOGGER.info(inputfile.getName());

            String content = FileUtils.readFileToString(inputfile, Charsets.UTF_8);

            StringBuffer newContent = new StringBuffer();
            newContent.append("<root>\n");
            newContent.append(content
                    .replaceAll("<title>", "</num>\n<title>")
                    .replaceAll("<desc>", "</title>\n<desc>")
                    .replaceAll("<narr>", "</desc>\n<narr>")
                    .replaceAll("</top>", "</narr>\n</top>")
                    .replaceAll("R&D", "R&amp;D")
            );
            newContent.append("</root>\n");

            Document doc = dBuilder.parse(new ByteArrayInputStream(newContent.toString().getBytes(Charsets.UTF_8)));
            for (Element element : JOOX.$(doc).find("top")) {
                Element numElement = JOOX.$(element).find("num").get(0);
                Element titleElement = JOOX.$(element).find("title").get(0);
                Element descElement = JOOX.$(element).find("desc").get(0);

                String number = "q" + numElement.getTextContent().trim().substring(7).trim();
                String title = titleElement.getTextContent().trim().replaceAll("\\s+", " ");
                String desc = descElement.getTextContent().trim().substring(12).trim().replaceAll("\\s+", " ");

                saveFile(outputFolder.getAbsolutePath() + "/keyword/" + number + ".naf", title, number, urlTemplate);
                saveFile(outputFolder.getAbsolutePath() + "/desc/" + number + ".naf", desc, number, urlTemplate);
                saveFile(outputFolder.getAbsolutePath() + "/keyword_desc/" + number + ".naf", title+".\n"+desc, number, urlTemplate);

            }

        } catch (Exception e) {
            CommandLine.fail(e);
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:63,代码来源:Queries.java

示例8: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            final CommandLine cmd = CommandLine
                    .parser()
                    .withName("fbis-extractor")
                    .withHeader("Extract FBIS documents from TREC dataset and save them in NAF format")
                    .withOption("i", "input", "Input folder", "FOLDER", CommandLine.Type.DIRECTORY_EXISTING, true,
                            false, true)
                    .withOption("o", "output", "Output folder", "FOLDER", CommandLine.Type.DIRECTORY, true, false, true)
                    .withOption("u", "url-template", "URL template (with %d for the ID)", "URL",
                            CommandLine.Type.STRING, true, false, false)
                    .withLogger(LoggerFactory.getLogger("eu.fbk")) //
                    .parse(args);

            File inputDir = cmd.getOptionValue("input", File.class);

            String urlTemplate = DEFAULT_URL;
            if (cmd.hasOption("url-template")) {
                urlTemplate = cmd.getOptionValue("url-template", String.class);
            }

            File outputDir = cmd.getOptionValue("output", File.class);
            if (!outputDir.exists()) {
                outputDir.mkdirs();
            }

            for (final File file : Files.fileTreeTraverser().preOrderTraversal(inputDir)) {
                if (!file.isFile()) {
                    continue;
                }
                if (file.getName().startsWith(".")) {
                    continue;
                }

                String outputTemplate = outputDir.getAbsolutePath() + File.separator + file.getName();
                File newFolder = new File(outputTemplate);
                newFolder.mkdirs();

                outputTemplate += File.separator + "NAF";
                saveFile(file, outputTemplate, urlTemplate);
            }
        } catch (Exception e) {
            CommandLine.fail(e);
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:48,代码来源:FBIS.java

示例9: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(final String[] args) throws IOException, XMLStreamException {
	try {
		final CommandLine cmd = CommandLine
				.parser()
				.withName("corpus-preprocessor")
				.withHeader(
						"Produces NAF files, a TSV file with sentiment annotations "
								+ "and an HTML file with annotated sentences "
								+ "starting from the MPQA v.2 corpus")
				.withOption("i", "input-path", "the base path of the MPQA corpus", "DIR",
						CommandLine.Type.DIRECTORY_EXISTING, true, false, true)
				.withOption("f", "filelist",
						String.format("the file with the docs filenames (relative to input path), default [basedir]/%s", DEFAULT_DOCS_LIST), "FILE",
						CommandLine.Type.FILE_EXISTING, true, false, false)
				.withOption("o", "output",
						String.format("the output path where to save produced files, default [basedir]/%s", DEFAULT_NAF_DIR),
						"DIR", CommandLine.Type.DIRECTORY_EXISTING, true, false, false)
				.withOption("n", "namespace",
						String.format("the namespace for generating document URIs, default %s", DEFAULT_NAMESPACE),
						"NS", CommandLine.Type.STRING, true, false, false)
				.withOption("doc", "doc", "Check only one document", "URL", CommandLine.Type.STRING, true, false, false)
				.withLogger(LoggerFactory.getLogger("eu.fbk.fssa")).parse(args);

		final File inputPath = cmd.getOptionValue("i", File.class);

		File outputPath = new File(inputPath.getAbsolutePath() + File.separator + DEFAULT_NAF_DIR);
		if (cmd.hasOption("o")) {
			outputPath = cmd.getOptionValue("o", File.class);
		}
		if (!outputPath.exists()) {
			outputPath.mkdirs();
		}

		File filelist = new File(inputPath.getAbsolutePath() + File.separator + DEFAULT_DOCS_LIST);
		if (cmd.hasOption("f")) {
			filelist = cmd.getOptionValue("f", File.class);
		}

		String namespace = DEFAULT_NAMESPACE;
		if (cmd.hasOption("n")) {
			namespace = cmd.getOptionValue("n", String.class);
		}

		String checkOneDoc = cmd.getOptionValue("doc", String.class);

		preprocess(inputPath, outputPath, filelist, namespace, checkOneDoc);

	} catch (final Throwable ex) {
		CommandLine.fail(ex);
	}
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:52,代码来源:CorpusPreprocessor.java

示例10: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        final CommandLine cmd = CommandLine
                .parser()
                .withName("./taol-extractor")
                .withHeader("Convert file from SignalMedia JSON to NAF")
                .withOption("i", "input", "Input file", "FILE",
                        CommandLine.Type.FILE_EXISTING, true, false, true)
                .withOption("o", "output", "Output folder", "FOLDER",
                        CommandLine.Type.DIRECTORY, true, false, true)
                .withOption("p", "prefix", String.format("Prefix (default %s)", DEFAULT_PREFIX), "PREFIX",
                        CommandLine.Type.STRING, true, false, false)
                .withOption("t", "skip-title", "Do not insert title into text")
                .withLogger(LoggerFactory.getLogger("eu.fbk")).parse(args);

        File inputFile = cmd.getOptionValue("input", File.class);
        File outputFolder = cmd.getOptionValue("output", File.class);
        String prefix = cmd.getOptionValue("prefix", String.class, DEFAULT_PREFIX);

        boolean skipTitle = cmd.hasOption("skip-title");

        if (!outputFolder.exists()) {
            outputFolder.mkdirs();
        }

        InputStream fileStream = new FileInputStream(inputFile);
        InputStream gzipStream = new GZIPInputStream(fileStream);
        Reader decoder = new InputStreamReader(gzipStream, Charset.forName("UTF-8"));
        BufferedReader reader = new BufferedReader(decoder);

        String line;
        while ((line = reader.readLine()) != null) {
            ObjectMapper mapper = new ObjectMapper();
            Map<String, Object> rootNode = mapper.readValue(line, Map.class);

            String id = (String) rootNode.get("id");
            String content = (String) rootNode.get("content");
            String title = (String) rootNode.get("title");
            String mediaType = (String) rootNode.get("media-type");
            String source = (String) rootNode.get("source");
            String published = (String) rootNode.get("published");

            if (!skipTitle) {
                content = title + "\n\n" + content;
            }

            // Fix a stupid bug in the dataset
            content = content.replaceAll("]]>", "");

            String simpleID = id.replaceAll("[^0-9a-zA-Z]", "");
            String subFolder = simpleID.substring(0, 2);
            File subFolderFile = new File(outputFolder + File.separator + subFolder);
            subFolderFile.mkdirs();

            String url = prefix + id;
            String outputFile = outputFolder + File.separator + subFolder + File.separator + id + ".naf";

            KAFDocument document = new KAFDocument("en", "v3");

            KAFDocument.Public documentPublic = document.createPublic();
            documentPublic.uri = url;
            documentPublic.publicId = id;

            KAFDocument.FileDesc documentFileDesc = document.createFileDesc();
            documentFileDesc.filename = id + ".naf";
            documentFileDesc.title = title;
            documentFileDesc.creationtime = published;
            documentFileDesc.author = source;
            documentFileDesc.filetype = mediaType;

            document.setRawText(content);

            document.save(outputFile);
        }
        reader.close();

    } catch (Exception e) {
        CommandLine.fail(e);
    }
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:81,代码来源:JsonToNaf.java

示例11: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(final String... args) {

        try {
            // Parse command line
            final CommandLine cmd = CommandLine
                    .parser()
                    .withName("eval-converter")
                    .withHeader("Convert a tool output in the format used for the evaluation.")
                    .withOption("o", "output", "the output file", "FILE", Type.STRING, true,
                            false, true)
                    .withOption("f", "format", "the format (fred, pikes, gold)", "FMT",
                            Type.STRING, true, false, true)
                    .withOption("n", "replace-nominal",
                            "replaces nominal frames with association " //
                                    + " relations (for FRED compatibility)")
                    .withLogger(LoggerFactory.getLogger("eu.fbk")) //
                    .parse(args);

            // Extract options
            final String format = cmd.getOptionValue("f", String.class).trim().toLowerCase();
            final String outputFile = cmd.getOptionValue("o", String.class);
            final List<String> inputFiles = cmd.getArgs(String.class);
            final boolean replaceNominalFrames = cmd.hasOption("n");

            // Obtain the converter corresponding to the format specified
            Converter converter;
            if (format.equalsIgnoreCase("fred")) {
                converter = FRED_CONVERTER;
            } else if (format.equalsIgnoreCase("gold")) {
                converter = GOLD_CONVERTER;
            } else if (format.equalsIgnoreCase("pikes")) {
                converter = PIKES_CONVERTER;
            } else {
                throw new IllegalArgumentException("Unknown format: " + format);
            }

            // Read the input
            final Map<String, String> namespaces = Maps.newHashMap();
            final QuadModel input = QuadModel.create();
            RDFSources.read(false, false, null, null,
                    inputFiles.toArray(new String[inputFiles.size()])).emit(
                    RDFHandlers.wrap(input, namespaces), 1);

            // Perform the conversion
            final QuadModel output = converter.convert(input);

            // Replace nominal frames if requested
            if (replaceNominalFrames) {
                replaceNominalFrames(output);
            }

            // Write the output
            final RDFHandler out = RDFHandlers.write(null, 1000, outputFile);
            out.startRDF();
            namespaces.put(DCTERMS.PREFIX, DCTERMS.NAMESPACE);
            namespaces.put("pb", "http://pikes.fbk.eu/ontologies/propbank#");
            namespaces.put("nb", "http://pikes.fbk.eu/ontologies/nombank#");
            namespaces.put("vn", "http://pikes.fbk.eu/ontologies/verbnet#");
            namespaces.put("fn", "http://pikes.fbk.eu/ontologies/framenet#");
            namespaces.put("dul", "http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#");
            final Set<String> outputNS = Sets.newHashSet();
            collectNS(outputNS, output);
            for (final Map.Entry<String, String> entry : namespaces.entrySet()) {
                if (!entry.getKey().isEmpty() && outputNS.contains(entry.getValue())) {
                    out.handleNamespace(entry.getKey(), entry.getValue());
                }
            }
            for (final Statement stmt : Ordering.from(
                    Statements.statementComparator("cspo",
                            Statements.valueComparator(RDF.NAMESPACE))).sortedCopy(output)) {
                out.handleStatement(stmt);
            }
            out.endRDF();

        } catch (final Throwable ex) {
            // Display error information and terminate
            CommandLine.fail(ex);
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:80,代码来源:Converter.java

示例12: main

import eu.fbk.utils.core.CommandLine; //导入方法依赖的package包/类
public static void main(final String... args) {
    try {
        LogManager.getLogManager().reset();
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        // Parse command line
        final CommandLine cmd = CommandLine
                .parser()
                .withName("kv-index")
                .withOption("c", "component",
                        "the component (s,p,o,c) to use for partitioning quads (default: s)",
                        "COMP", CommandLine.Type.STRING, true, false, false)
                .withOption("r", "recursive", "whether to recurse into input directories")
                .withOption("o", "output", "output file name", "FILE", CommandLine.Type.FILE,
                        true, false, true)
                .withHeader(
                        "Read RDF quads, split them into partitions by component "
                                + "and index the partitions in a binary file for fast lookup")
                .parse(args);

        // Extract options
        final StatementComponent component = StatementComponent.forLetter(cmd.getOptionValue(
                "c", String.class, "s").charAt(0));
        final boolean recursive = cmd.hasOption("r");
        final File output = cmd.getOptionValue("o", File.class);
        final List<File> files = cmd.getArgs(File.class);

        // Expand file list if recursive
        final Set<String> locations = Sets.newHashSet();
        for (final File file : files) {
            locations.add(file.getAbsolutePath());
            if (recursive && file.isDirectory()) {
                for (final File child : Files.fileTreeTraverser().preOrderTraversal(file)) {
                    if (Rio.getParserFormatForFileName(file.getAbsolutePath()) != null) {
                        locations.add(child.getAbsolutePath());
                    }
                }
            }
        }

        // Build the indexer
        final RDFHandler indexer = indexer(output, component);

        // Run the indexer
        RDFProcessors.read(true, true, null, null,
                locations.toArray(new String[locations.size()])).apply(RDFSources.NIL,
                indexer, 1);

    } catch (final Throwable ex) {
        // Display error information and terminate
        CommandLine.fail(ex);
    }
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:55,代码来源:KeyQuadIndex.java


注:本文中的eu.fbk.utils.core.CommandLine.hasOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。