List of usage examples for java.util Collection isEmpty
boolean isEmpty();
From source file:de.tudarmstadt.ukp.argumentation.cleaning.DataCleaner.java
public static void main(String[] args) throws Exception { // default path File dataDir = new File("data/"); // or from parameters if (args.length > 0) { dataDir = new File(args[0]); }/*from w w w .ja v a2s .c o m*/ Collection<File> files = FileUtils.listFiles(dataDir, new String[] { "txt" }, true); if (files.isEmpty()) { throw new IllegalArgumentException("No .txt files found in " + dataDir); } for (File file : files) { String text = FileUtils.readFileToString(file, "utf-8"); // cleaning String normalized = TextCleaningUtils.normalize(text); // and write back FileUtils.writeStringToFile(file, normalized, "utf-8"); } }
From source file:Department.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();// w ww. j av a2 s . c o m Professor emp = service.createProfessor("empName", 100); Department dept = service.createDepartment("deptName"); emp = service.setProfessorDepartment(emp.getId(), dept.getId()); System.out.println(emp.getDepartment() + " with Professors:"); System.out.println(emp.getDepartment().getProfessors()); Collection<Professor> emps = service.findAllProfessors(); if (emps.isEmpty()) { System.out.println("No Professors found "); } else { System.out.println("Found Professors:"); for (Professor emp1 : emps) { System.out.println(emp1); } } Collection<Department> depts = service.findAllDepartments(); if (depts.isEmpty()) { System.out.println("No Departments found "); } else { System.out.println("Found Departments:"); for (Department dept1 : depts) { System.out.println(dept1 + " with " + dept1.getProfessors().size() + " employees"); } } util.checkData("select * from Professor"); util.checkData("select * from Department"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Department.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();//from ww w . j a v a2 s.c o m Professor emp = service.createProfessor("empName", 100L); Department dept = service.createDepartment("deptName"); emp = service.setProfessorDepartment(emp.getId(), dept.getId()); System.out.println(emp.getDepartment() + " with Professors:"); System.out.println(emp.getDepartment().getProfessors()); Collection<Professor> emps = service.findAllProfessors(); if (emps.isEmpty()) { System.out.println("No Professors found "); } else { System.out.println("Found Professors:"); for (Professor emp1 : emps) { System.out.println(emp1); } } Collection<Department> depts = service.findAllDepartments(); if (depts.isEmpty()) { System.out.println("No Departments found "); } else { System.out.println("Found Departments:"); for (Department dept1 : depts) { System.out.println( dept1 + " with " + dept1.getProfessors().size() + " employees " + dept1.getProfessors()); } } util.checkData("select * from Professor"); util.checkData("select * from Department"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Department.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*from w w w .j a v a 2s .co m*/ Professor emp = service.createProfessor("empName", 100L); Department dept = service.createDepartment("deptName"); emp = service.setProfessorDepartment(emp.getId(), dept.getId()); System.out.println(emp.getDepartment() + " with Professors:"); System.out.println(emp.getDepartment().getProfessors()); Collection<Professor> emps = service.findAllProfessors(); if (emps.isEmpty()) { System.out.println("No Professors found "); } else { System.out.println("Found Professors:"); for (Professor emp1 : emps) { System.out.println(emp1); } } Collection<Department> depts = service.findAllDepartments(); if (depts.isEmpty()) { System.out.println("No Departments found "); } else { System.out.println("Found Departments:"); for (Department dept1 : depts) { System.out.println( dept1 + " with " + dept1.getProfessors().size() + " employees " + dept1.getProfessors()); } } util.checkData("select * from Professor"); util.checkData("select * from Department"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Professor.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*from w w w . ja v a 2s. co m*/ Professor emp = service.createProfessor("empName", 100); Project proj = service.createProject("projName"); emp = service.addProfessorProject(emp.getId(), proj.getId()); Collection<Professor> emps = service.findAllProfessors(); if (emps.isEmpty()) { System.out.println("No Professors found "); } else { System.out.println("Found Professors:"); for (Professor emp1 : emps) { System.out.println(emp1); } } Collection<Project> projs = service.findAllProjects(); if (projs.isEmpty()) { System.out.println("No Projects found "); } else { System.out.println("Found Projects:"); for (Project proj1 : projs) { System.out.println(proj1); } } util.checkData("select * from Professor"); util.checkData("select * from Project"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:eu.annocultor.utils.OntologySubtractor.java
public static void main(String[] args) throws Exception { boolean copy = checkNoCopyOption(args); if (args.length == 2 || args.length == 3) { File sourceDir = new File(args[0]); File destinationDir = new File(args[1]); checkSrcAndDstDirs(sourceDir, destinationDir); Collection<String> filesWithDeletedStatements = listNameStamsForFilesWithDeletedStatements(sourceDir); if (filesWithDeletedStatements.isEmpty()) { System.out.println(//w ww . j a va2s . c o m "Did not found any file *.*.*.deleted.rdf with statements to be deleted. Do nothing and exit."); } else { System.out.println( "Found " + filesWithDeletedStatements.size() + " files with statements to be deleted"); System.out.println( "Copying all RDF files from " + sourceDir.getName() + " to " + destinationDir.getName()); if (copy) { copyRdfFiles(sourceDir, destinationDir); } sutractAll(sourceDir, destinationDir, filesWithDeletedStatements); } } else { for (Object string : IOUtils.readLines(new AutoCloseInputStream( OntologySubtractor.class.getResourceAsStream("/subtractor/readme.txt")))) { System.out.println(string.toString()); } } }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step7CollectMTurkResults.java
public static void main(String[] args) throws Exception { // input dir - list of xml query containers // /home/user-ukp/research/data/dip/wp1-documents/step4-boiler-plate/ File inputDir = new File(args[0] + "/"); // MTurk result file // output dir File outputDir = new File(args[2]); if (!outputDir.exists()) { outputDir.mkdirs();//from w ww .java 2s .c om } // Folder with success files File mturkSuccessDir = new File(args[1]); Collection<File> files = FileUtils.listFiles(mturkSuccessDir, new String[] { "result" }, false); if (files.isEmpty()) { throw new IllegalArgumentException("Input folder is empty. " + mturkSuccessDir); } HashMap<String, List<MTurkAnnotation>> mturkAnnotations = new HashMap<>(); // parsing all CSV files for (File mturkCSVResultFile : files) { System.out.println("Parsing " + mturkCSVResultFile.getName()); MTurkOutputReader outputReader = new MTurkOutputReader( new HashSet<>(Arrays.asList("annotation", "workerid")), mturkCSVResultFile); // for fixing broken data input: for each hit, collect all sentence IDs Map<String, SortedSet<String>> hitSentences = new HashMap<>(); // first iteration: collect the sentences for (Map<String, String> record : outputReader) { String hitID = record.get("hitid"); if (!hitSentences.containsKey(hitID)) { hitSentences.put(hitID, new TreeSet<>()); } String relevantSentences = record.get("Answer.relevant_sentences"); String irrelevantSentences = record.get("Answer.irrelevant_sentences"); if (relevantSentences != null) { hitSentences.get(hitID).addAll(Arrays.asList(relevantSentences.split(","))); } if (irrelevantSentences != null) { hitSentences.get(hitID).addAll(Arrays.asList(irrelevantSentences.split(","))); } } // and now second iteration for (Map<String, String> record : outputReader) { String hitID = record.get("hitid"); String annotatorID = record.get("workerid"); String acceptTime = record.get("assignmentaccepttime"); String submitTime = record.get("assignmentsubmittime"); String relevantSentences = record.get("Answer.relevant_sentences"); String irrelevantSentences = record.get("Answer.irrelevant_sentences"); String reject = record.get("reject"); String filename[]; String comment; String clueWeb; String[] relevant = {}; String[] irrelevant = {}; filename = record.get("annotation").split("_"); String fileXml = filename[0]; clueWeb = filename[1].trim(); comment = record.get("Answer.comment"); if (relevantSentences != null) { relevant = relevantSentences.split(","); } if (irrelevantSentences != null) { irrelevant = irrelevantSentences.split(","); } // sanitizing data: if both relevant and irrelevant are empty, that's a bug // we're gonna look up all sentences from this HIT and treat this assignment // as if there were only irrelevant ones if (relevant.length == 0 && irrelevant.length == 0) { SortedSet<String> strings = hitSentences.get(hitID); irrelevant = new String[strings.size()]; strings.toArray(irrelevant); } if (reject != null) { System.out.println(" HIT " + hitID + " annotated by " + annotatorID + " was rejected "); } else { /* // relevant sentences is a comma-delimited string, // this regular expression is rather strange // it must contain digits, it might be that there is only one space or a comma or some other char // digits are the sentence ids. if relevant sentences do not contain digits then it is wrong if (relevantSentences.matches("^\\D*$") && irrelevantSentences.matches("^\\D*$")) { try { throw new IllegalStateException( "No annotations found for HIT " + hitID + " in " + fileXml + " for document " + clueWeb); } catch (IllegalStateException ex) { ex.printStackTrace(); } } */ MTurkAnnotation mturkAnnotation; try { mturkAnnotation = new MTurkAnnotation(hitID, annotatorID, acceptTime, submitTime, comment, clueWeb, relevant, irrelevant); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException("Record: " + record, ex); } List<MTurkAnnotation> listOfAnnotations = mturkAnnotations.get(fileXml); if (listOfAnnotations == null) { listOfAnnotations = new ArrayList<>(); } listOfAnnotations.add(mturkAnnotation); mturkAnnotations.put(fileXml, listOfAnnotations); } } // parser.close(); } // Debugging: output number of HITs of a query System.out.println("Accepted HITs for a query:"); for (Map.Entry e : mturkAnnotations.entrySet()) { ArrayList<MTurkAnnotation> a = (ArrayList<MTurkAnnotation>) e.getValue(); System.out.println(e.getKey() + " " + a.size()); } for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); String fileName = f.getName(); List<MTurkAnnotation> listOfAnnotations = mturkAnnotations.get(fileName); if (listOfAnnotations == null || listOfAnnotations.isEmpty()) { throw new IllegalStateException("No annotations for " + f.getName()); } for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) { for (MTurkAnnotation mtAnnotation : listOfAnnotations) { String clueWeb = mtAnnotation.clueWeb; if (rankedResults.clueWebID.equals(clueWeb)) { List<QueryResultContainer.MTurkRelevanceVote> mTurkRelevanceVotes = rankedResults.mTurkRelevanceVotes; QueryResultContainer.MTurkRelevanceVote relevanceVote = new QueryResultContainer.MTurkRelevanceVote(); String annotatorID = mtAnnotation.annotatorID; String hitID = mtAnnotation.hitID; String acceptTime = mtAnnotation.acceptTime; String submitTime = mtAnnotation.submitTime; String comment = mtAnnotation.comment; String[] relevant = mtAnnotation.relevant; String[] irrelevant = mtAnnotation.irrelevant; relevanceVote.turkID = annotatorID.trim(); relevanceVote.hitID = hitID.trim(); relevanceVote.acceptTime = acceptTime.trim(); relevanceVote.submitTime = submitTime.trim(); relevanceVote.comment = comment != null ? comment.trim() : null; if (relevant.length == 0 && irrelevant.length == 0) { try { throw new IllegalStateException("the length of the annotations is 0" + rankedResults.clueWebID + " for HIT " + relevanceVote.hitID); } catch (IllegalStateException e) { e.printStackTrace(); } } for (String r : relevant) { String sentenceId = r.trim(); if (!sentenceId.isEmpty() && sentenceId.matches("\\d+")) { QueryResultContainer.SingleSentenceRelevanceVote singleSentenceVote = new QueryResultContainer.SingleSentenceRelevanceVote(); singleSentenceVote.sentenceID = sentenceId; singleSentenceVote.relevant = "true"; relevanceVote.singleSentenceRelevanceVotes.add(singleSentenceVote); } } for (String r : irrelevant) { String sentenceId = r.trim(); if (!sentenceId.isEmpty() && sentenceId.matches("\\d+")) { QueryResultContainer.SingleSentenceRelevanceVote singleSentenceVote = new QueryResultContainer.SingleSentenceRelevanceVote(); singleSentenceVote.sentenceID = sentenceId; singleSentenceVote.relevant = "false"; relevanceVote.singleSentenceRelevanceVotes.add(singleSentenceVote); } } mTurkRelevanceVotes.add(relevanceVote); } } } File outputFile = new File(outputDir, f.getName()); FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8"); System.out.println("Finished " + outputFile); } }
From source file:cross.applicationContext.ReflectionApplicationContextGenerator.java
/** * * @param args/*from ww w. j a va 2s . co m*/ */ public static void main(String[] args) { String[] classes = args; String springVersion = "3.0"; String scope = "prototype"; //generate the application context XML ReflectionApplicationContextGenerator generator = new ReflectionApplicationContextGenerator(springVersion, scope); for (String className : classes) { try { Collection<?> serviceImplementations = Lookup.getDefault().lookupAll(Class.forName(className)); if (serviceImplementations.isEmpty()) { //standard bean, add it try { generator.addBean(className); } catch (ClassNotFoundException ex) { log.warn("Could not find class", ex); } } else {//service provider implementation for (Object obj : serviceImplementations) { try { generator.addBean(obj.getClass().getCanonicalName()); } catch (ClassNotFoundException ex) { log.warn("Could not find class", ex); } } } } catch (ClassNotFoundException ex) { log.warn("Could not find class", ex); } } Document document = generator.getDocument(); writeToFile(document, new File("applicationContext.xml")); }
From source file:org.biopax.validator.BiopaxValidatorClient.java
/** * Checks BioPAX files using the online BioPAX Validator. * //from w w w . j a v a 2 s . c om * @see <a href="http://www.biopax.org/validator">BioPAX Validator Webservice</a> * * @param argv * @throws IOException */ public static void main(String[] argv) throws IOException { if (argv.length == 0) { System.err.println("Available parameters: \n" + "<path> <output> [xml|html|biopax] [auto-fix] [only-errors] [maxerrors=n] [notstrict]\n" + "\t- validate a BioPAX file/directory (up to ~25MB in total size, -\n" + "\totherwise, please use the biopax-validator.jar instead)\n" + "\tin the directory using the online BioPAX Validator service\n" + "\t(generates html or xml report, or gets the processed biopax\n" + "\t(cannot fix all errros though) see http://www.biopax.org/validator)"); System.exit(-1); } final String input = argv[0]; final String output = argv[1]; File fileOrDir = new File(input); if (!fileOrDir.canRead()) { System.err.println("Cannot read from " + input); System.exit(-1); } if (output == null || output.isEmpty()) { System.err.println("No output file specified (for the validation report)."); System.exit(-1); } // default options RetFormat outf = RetFormat.HTML; boolean fix = false; Integer maxErrs = null; Behavior level = null; //will report both errors and warnings String profile = null; // match optional arguments for (int i = 2; i < argv.length; i++) { if ("html".equalsIgnoreCase(argv[i])) { outf = RetFormat.HTML; } else if ("xml".equalsIgnoreCase(argv[i])) { outf = RetFormat.XML; } else if ("biopax".equalsIgnoreCase(argv[i])) { outf = RetFormat.OWL; } else if ("auto-fix".equalsIgnoreCase(argv[i])) { fix = true; } else if ("only-errors".equalsIgnoreCase(argv[i])) { level = Behavior.ERROR; } else if ((argv[i]).toLowerCase().startsWith("maxerrors=")) { String num = argv[i].substring(10); maxErrs = Integer.valueOf(num); } else if ("notstrict".equalsIgnoreCase(argv[i])) { profile = "notstrict"; } } // collect files Collection<File> files = new HashSet<File>(); if (fileOrDir.isDirectory()) { // validate all the OWL files in the folder FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(".owl")); } }; for (String s : fileOrDir.list(filter)) { files.add(new File(fileOrDir.getCanonicalPath() + File.separator + s)); } } else { files.add(fileOrDir); } // upload and validate using the default URL: http://www.biopax.org/biopax-validator/check.html if (!files.isEmpty()) { BiopaxValidatorClient val = new BiopaxValidatorClient(); val.validate(fix, profile, outf, level, maxErrs, null, files.toArray(new File[] {}), new FileOutputStream(output)); } }
From source file:net.sf.jabref.logic.xmp.XMPUtil.java
/** * Command-line tool for working with XMP-data. * * Read or write XMP-metadata from or to pdf file. * * Usage://from w w w . j a v a 2 s. c o m * <dl> * <dd>Read from PDF and print as bibtex:</dd> * <dt>xmpUtil PDF</dt> * <dd>Read from PDF and print raw XMP:</dd> * <dt>xmpUtil -x PDF</dt> * <dd>Write the entry in BIB given by KEY to the PDF:</dd> * <dt>xmpUtil KEY BIB PDF</dt> * <dd>Write all entries in BIB to the PDF:</dd> * <dt>xmpUtil BIB PDF</dt> * </dl> * * @param args * Command line strings passed to utility. * @throws IOException * If any of the given files could not be read or written. * @throws TransformerException * If the given BibEntry is malformed. */ public static void main(String[] args) throws IOException, TransformerException { // Don't forget to initialize the preferences if (Globals.prefs == null) { Globals.prefs = JabRefPreferences.getInstance(); } switch (args.length) { case 0: XMPUtil.usage(); break; case 1: if (args[0].endsWith(".pdf")) { // Read from pdf and write as BibTex List<BibEntry> l = XMPUtil.readXMP(new File(args[0]), Globals.prefs); BibEntryWriter bibtexEntryWriter = new BibEntryWriter( new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), false); for (BibEntry entry : l) { StringWriter sw = new StringWriter(); bibtexEntryWriter.write(entry, sw, BibDatabaseMode.BIBTEX); System.out.println(sw.getBuffer()); } } else if (args[0].endsWith(".bib")) { // Read from bib and write as XMP try (FileReader fr = new FileReader(args[0])) { ParserResult result = BibtexParser.parse(fr); Collection<BibEntry> entries = result.getDatabase().getEntries(); if (entries.isEmpty()) { System.err.println("Could not find BibEntry in " + args[0]); } else { System.out.println(XMPUtil.toXMP(entries, result.getDatabase())); } } } else { XMPUtil.usage(); } break; case 2: if ("-x".equals(args[0]) && args[1].endsWith(".pdf")) { // Read from pdf and write as BibTex Optional<XMPMetadata> meta = XMPUtil.readRawXMP(new File(args[1])); if (meta.isPresent()) { XMLUtil.save(meta.get().getXMPDocument(), System.out, StandardCharsets.UTF_8.name()); } else { System.err.println("The given pdf does not contain any XMP-metadata."); } break; } if (args[0].endsWith(".bib") && args[1].endsWith(".pdf")) { ParserResult result = BibtexParser.parse(new FileReader(args[0])); Collection<BibEntry> entries = result.getDatabase().getEntries(); if (entries.isEmpty()) { System.err.println("Could not find BibEntry in " + args[0]); } else { XMPUtil.writeXMP(new File(args[1]), entries, result.getDatabase(), false); System.out.println("XMP written."); } break; } XMPUtil.usage(); break; case 3: if (!args[1].endsWith(".bib") && !args[2].endsWith(".pdf")) { XMPUtil.usage(); break; } ParserResult result = BibtexParser.parse(new FileReader(args[1])); Optional<BibEntry> bibEntry = result.getDatabase().getEntryByKey(args[0]); if (bibEntry.isPresent()) { XMPUtil.writeXMP(new File(args[2]), bibEntry.get(), result.getDatabase()); System.out.println("XMP written."); } else { System.err.println("Could not find BibEntry " + args[0] + " in " + args[0]); } break; default: XMPUtil.usage(); } }