List of usage examples for java.util HashSet contains
public boolean contains(Object o)
From source file:dpfmanager.conformancechecker.tiff.implementation_checker.TiffImplementationChecker.java
public TiffIfd CreateIFDValidation(IFD ifd, int n) { boolean hasSubIfd = ifd.hasSubIFD(); boolean thumbnail = hasSubIfd && ifd.getsubIFD().getImageSize() > ifd.getImageSize(); IfdTags metadata;// w ww.j a v a 2 s . c om if (!hasSubIfd) { metadata = ifd.getMetadata(); } else if (!thumbnail) { metadata = ifd.getMetadata(); } else { metadata = ifd.getsubIFD().getMetadata(); } TiffIfd tiffIfd = new TiffIfd(); tiffIfd.setN(n); tiffIfd.setThumbnail(ifd.isThumbnail() ? 1 : 0); List<TiffTag> tags = new ArrayList<TiffTag>(); int prevTagId = -1; boolean correctTagOrdering = true; boolean duplicatedTags = false; boolean correctCompression = true; boolean correctPhotometricCasuistic = true; boolean correctYcbcr = true; HashSet tagIds = new HashSet<>(); for (TagValue tv : ifd.getTags().getTags()) { try { if (tv.getId() <= prevTagId) { correctTagOrdering = false; } if (tagIds.contains(tv.getId())) { duplicatedTags = true; } else { tagIds.add(tv.getId()); } prevTagId = tv.getId(); tags.add(CreateTiffTag(tv, n)); usedOffsetsSizes.put(tv.getReadOffset(), tv.getReadlength()); } catch (Exception ex) { ex.printStackTrace(); } } TiffTags tiffTags = new TiffTags(); tiffTags.setTags(tags); tiffTags.setTagsCount(tags.size()); tiffIfd.setTags(tiffTags); tiffIfd.setTagOrdering(correctTagOrdering ? 1 : 0); tiffIfd.setDuplicateTags(duplicatedTags ? 1 : 0); tiffIfd.setStrips(ifd.hasStrips() ? 1 : 0); tiffIfd.setTiles(ifd.hasTiles() ? 1 : 0); tiffIfd.setCorrectStrips(1); tiffIfd.setCorrectTiles(1); tiffIfd.setOffset(ifd.getNextOffset()); tiffIfd.setIFD0(n == 1 ? 1 : 0); // Strips check if (ifd.hasStrips()) { int pixelSize = 0; for (int i = 0; i < metadata.get("BitsPerSample").getCardinality(); i++) { pixelSize += metadata.get("BitsPerSample").getValue().get(i).toInt(); } int id = com.easyinnova.tiff.model.TiffTags.getTagId("StripBYTECount"); int nsc = metadata.get(id).getCardinality(); if (metadata.get("Compression").getFirstNumericValue() == 1 && pixelSize >= 8) { int calculatedImageLength = 0; for (int i = 0; i < nsc; i++) { calculatedImageLength += metadata.get(id).getValue().get(i).toInt(); } if (calculatedImageLength != metadata.get("ImageLength").getFirstNumericValue() * metadata.get("ImageWidth").getFirstNumericValue() * pixelSize / 8) { tiffIfd.setCorrectStrips(0); } } //long rps = 1; //if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("RowsPerStrip"))) // rps = metadata.get("RowsPerStrip").getFirstNumericValue(); //long leng = metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("ImageLength")).getFirstNumericValue(); //int nstrips = (int)Math.ceil((double)leng / rps); //if (nstrips != nsc) // tiffIfd.setCorrectStrips(0); } // Tiles check if (ifd.hasTiles()) { long tileLength = metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("TileLength")) .getFirstNumericValue(); ; long tileWidth = metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("TileWidth")) .getFirstNumericValue(); ; long tilesPerImage = ((metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("ImageWidth")) .getFirstNumericValue() + tileWidth - 1) / tileWidth) * ((metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("ImageLength")) .getFirstNumericValue() + tileLength - 1) / tileLength); // Check Plannar Configuration int id = com.easyinnova.tiff.model.TiffTags.getTagId("PlanarConfiguration"); int idspp = com.easyinnova.tiff.model.TiffTags.getTagId("SamplesPerPixel"); if (metadata.containsTagId(id) && metadata.containsTagId(idspp)) { long planar = metadata.get(id).getFirstNumericValue(); long spp = metadata.get(idspp).getFirstNumericValue(); if (planar == 2) { long spp_tpi = spp * tilesPerImage; if (ifd.getImageTiles().getTiles().size() < spp_tpi) { tiffIfd.setCorrectTiles(0); } } } } // Check pixel samples bits if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("BitsPerSample")) && metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("SamplesPerPixel"))) { boolean correctExtraSamples = true; boolean onlyNecessaryExtraSamples = true; boolean validBitsPerSample = true; boolean equalBitsPerSampleValues = true; int bps = metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("BitsPerSample")).getValue().size(); if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("ExtraSamples"))) { int ext = metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("ExtraSamples")).getValue() .size(); if (ext + 3 != bps) { correctExtraSamples = false; } else if (ext > 0 && bps <= 3) { onlyNecessaryExtraSamples = false; } } if (bps > 1) { TagValue lbps = metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("BitsPerSample")); if (lbps == null || lbps.getValue() == null) { validBitsPerSample = false; } else { boolean distinct_bps_samples = false; for (int i = 1; i < lbps.getCardinality(); i++) { if (lbps.getValue().get(i).toInt() != lbps.getValue().get(i - 1).toInt()) distinct_bps_samples = true; } if (distinct_bps_samples) equalBitsPerSampleValues = false; } } // Check correct compression if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("Compression")) && metadata.get("Compression").getFirstNumericValue() == 1) { if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("CompressedBitsPerPixel"))) { correctCompression = false; } } // Check photometric casuistic if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("PhotometricInterpretation"))) { int photo = (int) metadata.get("PhotometricInterpretation").getFirstNumericValue(); if (photo != 6) { if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrCoefficients"))) correctPhotometricCasuistic = false; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrSubSampling"))) correctPhotometricCasuistic = false; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrPositioning"))) correctPhotometricCasuistic = false; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("ReferenceBlackWhite"))) correctPhotometricCasuistic = false; } long spp = 0; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("SamplesPerPixel"))) spp = metadata.get("SamplesPerPixel").getFirstNumericValue(); if (photo == 2 || photo == 3) { if (spp != 3) { correctPhotometricCasuistic = false; } } else if (photo == 1 || photo == 32803) { if (spp != 1) { correctPhotometricCasuistic = false; } if (photo == 32803) { if (!metadata .containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("CFARepeatPatternDim"))) correctPhotometricCasuistic = false; else if (metadata.get("CFARepeatPatternDim").getCardinality() != 2) correctPhotometricCasuistic = false; if (!metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("CFAPattern"))) correctPhotometricCasuistic = false; } } } // Check YcbCr int nycbcr = 0; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrCoefficients"))) nycbcr++; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrSubSampling"))) nycbcr++; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrPositioning"))) nycbcr++; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("ReferenceBlackWhite"))) nycbcr++; if (nycbcr > 0 && nycbcr != 4) { if (!metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("CFARepeatPatternDim"))) correctYcbcr = false; else if (metadata.get("CFARepeatPatternDim").getCardinality() != 3) correctPhotometricCasuistic = false; if (!metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrSubSampling"))) correctYcbcr = false; else if (metadata.get("YCbCrSubSampling").getCardinality() != 2) correctPhotometricCasuistic = false; if (!metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrPositioning"))) correctYcbcr = false; else if (metadata.get("YCbCrPositioning").getCardinality() != 1) correctPhotometricCasuistic = false; if (!metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("ReferenceBlackWhite"))) correctYcbcr = false; else if (metadata.get("ReferenceBlackWhite").getCardinality() != 6) correctPhotometricCasuistic = false; } if (thumbnail) { if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrCoefficients"))) correctYcbcr = false; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrSubSampling"))) correctYcbcr = false; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YCbCrPositioning"))) correctYcbcr = false; if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("ReferenceBlackWhite"))) correctYcbcr = false; } // IT Fields if (setITFields) { setITFields(ifd, tiffIfd); } tiffIfd.setCorrectExtraSamples(correctExtraSamples ? 1 : 0); tiffIfd.setOnlyNecessaryExtraSamples(onlyNecessaryExtraSamples ? 1 : 0); tiffIfd.setValidBitsPerSample(validBitsPerSample ? 1 : 0); tiffIfd.setEqualBitsPerSampleValues(equalBitsPerSampleValues ? 1 : 0); tiffIfd.setCorrectCompression(correctCompression ? 1 : 0); tiffIfd.setCorrectPhotometricCasuistic(correctPhotometricCasuistic ? 1 : 0); tiffIfd.setCorrectYcbcr(correctYcbcr ? 1 : 0); } // Check image type if (metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("PhotometricInterpretation"))) { int photometric = (int) metadata .get(com.easyinnova.tiff.model.TiffTags.getTagId("PhotometricInterpretation")) .getFirstNumericValue(); switch (photometric) { case 0: case 1: if (!metadata.containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("BitsPerSample")) || metadata.get(com.easyinnova.tiff.model.TiffTags.getTagId("BitsPerSample")) .getFirstNumericValue() == 1) { tiffIfd.setType("Bilevel"); } else { tiffIfd.setType("Grayscale"); } break; case 2: tiffIfd.setType("RGB"); break; case 3: tiffIfd.setType("Palette"); break; case 4: tiffIfd.setType("Transparency"); break; case 5: tiffIfd.setType("CMYK"); break; case 6: tiffIfd.setType("YCbCr"); break; case 8: case 9: case 10: tiffIfd.setType("CIELab"); break; } } // Policy fields if (ifd.getMetadata() != null && ifd.getMetadata().get("BitsPerSample") != null) { String bps = ifd.getMetadata().get("BitsPerSample").toString(); tiffIfd.setBitDepth(bps); } String eqxy = "True"; if (ifd.getTags().containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("XResolution")) && ifd.getTags().containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YResolution"))) { if (!ifd.getTag("XResolution").toString().equals(ifd.getTag("YResolution").toString())) eqxy = "False"; } tiffIfd.setEqualXYResolution(eqxy); String dpi = ""; if (ifd.getTags().containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("XResolution")) && ifd.getTags().containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("YResolution"))) { try { Rational ratx = (Rational) ifd.getTag("XResolution").getValue().get(0); Rational raty = (Rational) ifd.getTag("YResolution").getValue().get(0); int xres = (int) ratx.getFloatValue(); int yres = (int) raty.getFloatValue(); if (xres % 2 != 0 || yres % 2 != 0) dpi = "Uneven"; else dpi = "Even"; } catch (Exception ex) { ex.printStackTrace(); } } tiffIfd.setDpi(dpi); String extra = "0"; if (ifd.getTags().containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("ExtraSamples"))) extra = ifd.getTag("ExtraSamples").getCardinality() + ""; tiffIfd.setExtraChannels(extra); String pixeldensity = "0"; if (ifd.getMetadata() != null && ifd.getMetadata().containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("ResolutionUnit")) && ifd.getMetadata().containsTagId(com.easyinnova.tiff.model.TiffTags.getTagId("XResolution"))) { try { double ru = Double.parseDouble(ifd.getMetadata().get("ResolutionUnit").toString()); String xres = ifd.getMetadata().get("XResolution").toString(); double num = Double.parseDouble(xres.substring(0, xres.indexOf("/"))); double den = Double.parseDouble(xres.substring(xres.indexOf("/") + 1)); double xr = num / den; double ppi; if (ru == 2) ppi = xr; else ppi = xr / 0.3937; pixeldensity = ppi + ""; } catch (Exception ex) { pixeldensity = ""; } } tiffIfd.setPixelDensity(pixeldensity); return tiffIfd; }
From source file:HLA.java
private boolean checkHeader(SAMFileHeader header) { List<SAMSequenceRecord> sequences = header.getSequenceDictionary().getSequences(); HashSet<String> map = new HashSet<String>(); //load kourami panel sequence names BufferedReader br;// w ww . ja v a 2 s . com try { br = new BufferedReader(new InputStreamReader(new GZIPInputStream( new FileInputStream(HLA.MSAFILELOC + File.separator + "All_FINAL_with_Decoy.fa.gz")))); String curline = ""; while ((curline = br.readLine()) != null) { if (curline.charAt(0) == ('>')) map.add(curline.substring(1)); } br.close(); } catch (IOException ioe) { ioe.printStackTrace(); } //check if input bam has sequences to kourami panel for (SAMSequenceRecord ssr : sequences) { if (!map.contains(ssr.getSequenceName())) return false; } return true; }
From source file:edu.arizona.kra.proposaldevelopment.dao.ojb.PropDevRoutingStateDaoOjb.java
@Override public List<ProposalDevelopmentRoutingState> getPropDevRoutingState(Map<String, String> searchCriteria) throws SQLException, LookupException { List<ProposalDevelopmentRoutingState> results = new ArrayList<ProposalDevelopmentRoutingState>(); HashSet<String> resultDocNumbers = new HashSet<String>(); LOG.debug("getPropDevRoutingState searchCriteria={}", searchCriteria); String sqlQuery = buildSqlQuery(searchCriteria); boolean displayAdHocNodes = (searchCriteria.containsKey(ROUTE_STOP_NAME) && StringUtils.isEmpty(searchCriteria.get(ROUTE_STOP_NAME))); try (DBConnection dbc = new DBConnection(this.getPersistenceBroker(true))) { ResultSet rs = dbc.executeQuery(sqlQuery, null); while (rs.next()) { String documentNumber = rs.getString(COL_DOCUMENT_NUMBER); String annotation = rs.getString(COL_ANNOTATION); //avoid displaying more than one result row per document if (!resultDocNumbers.contains(documentNumber)) { //skip AdHoc nodes if the searchCriteria has a specific NodeName if (isAdHocNode(annotation) && !displayAdHocNodes) { continue; }/* w w w. j a v a2 s .c o m*/ ProposalDevelopmentRoutingState rtState = new ProposalDevelopmentRoutingState(); rtState.setRouteStopDate(rs.getTimestamp(COL_STOP_DATE)); rtState.setRouteStopName(getRouteStopLabel(rs.getString(COL_NODE_NAME), annotation)); rtState.setProposalNumber(rs.getString(COL_PROPOSAL_NUMBER)); rtState.setProposalDocumentNumber(documentNumber); rtState.setProposalTitle(rs.getString(COL_PROPOSAL_TITLE)); rtState.setSponsorName(rs.getString(COL_SPONSOR_NAME)); rtState.setSponsorCode(rs.getString(COL_SPONSOR_CODE)); rtState.setSponsorDeadlineDate(rs.getDate(COL_SPONSOR_DEADLINE_DATE)); rtState.setSponsorDeadlineTime(rs.getString(COL_SPONSOR_DEADLINE_TIME)); rtState.setPrincipalInvestigatorName(rs.getString(COL_PRINCIPAL_INVESTIGATOR)); rtState.setLeadUnitNumber(rs.getString(COL_LEAD_UNIT)); rtState.setLeadUnitName(rs.getString(COL_LEAD_UNIT_NAME)); rtState.setLeadCollege(""); String ordExpedited = rs.getString(COL_ORD_EXP); rtState.setORDExpedited(YES.equalsIgnoreCase(ordExpedited)); String fpr = rs.getString(COL_FPR); rtState.setFinalProposalReceived(YES.equalsIgnoreCase(fpr)); rtState.setSPSPersonId(rs.getString(COL_SPS_REVIEWER_ID)); rtState.setSPSReviewerName(rs.getString(COL_SPS_REVIEWER_NAME)); results.add(rtState); resultDocNumbers.add(rtState.getProposalDocumentNumber()); } } } catch (SQLException sqle) { LOG.error("SQLException: " + sqle.getMessage(), sqle); throw sqle; } catch (LookupException le) { LOG.error("LookupException: " + le.getMessage(), le); throw le; } LOG.debug("getPropDevRoutingState: no of unfiltered results={}.", results.size()); //perform additional filtering on the results if the user specified a workflow unit if (!results.isEmpty() && searchCriteria.containsKey(WORKFLOW_UNIT) && StringUtils.isNotEmpty(searchCriteria.get(WORKFLOW_UNIT))) { String workflowUnit = searchCriteria.get(WORKFLOW_UNIT); List<String> workFlowUnits = findWorkflowUnitNumbers(workflowUnit); List<String> proposalNumbers = findProposalsForWorkflowUnits(workFlowUnits); List<ProposalDevelopmentRoutingState> filteredResults = new ArrayList<ProposalDevelopmentRoutingState>(); for (ProposalDevelopmentRoutingState rtState : results) { if (proposalNumbers.contains(rtState.getProposalNumber())) { filteredResults.add(rtState); } } LOG.debug("getPropDevRoutingState: filtered results={}.", filteredResults.size()); return filteredResults; } return results; }
From source file:com.rc.droid_stalker.components.NetworkStats.java
/** * Return total of all fields represented by this snapshot object matching * the requested {@link #iface} and {@link #uid}. * * @param limitIface Set of {@link #iface} to include in total; or {@code * null} to include all ifaces. *///from w w w . j a va 2s . c o m private Entry getTotal(Entry recycle, HashSet<String> limitIface, int limitUid, boolean includeTags) { final Entry entry = recycle != null ? recycle : new Entry(); entry.iface = IFACE_ALL; entry.uid = limitUid; entry.set = SET_ALL; entry.tag = TAG_NONE; entry.rxBytes = 0; entry.rxPackets = 0; entry.txBytes = 0; entry.txPackets = 0; entry.operations = 0; for (int i = 0; i < size; i++) { final boolean matchesUid = (limitUid == UID_ALL) || (limitUid == uid[i]); final boolean matchesIface = (limitIface == null) || (limitIface.contains(iface[i])); if (matchesUid && matchesIface) { // skip specific tags, since already counted in TAG_NONE if (tag[i] != TAG_NONE && !includeTags) continue; entry.rxBytes += rxBytes[i]; entry.rxPackets += rxPackets[i]; entry.txBytes += txBytes[i]; entry.txPackets += txPackets[i]; entry.operations += operations[i]; } } return entry; }
From source file:gedi.riboseq.inference.orf.OrfFinder.java
private GenomicRegion extendCorePath(GenomicRegion path, Codon from, Codon to, Intron intron, HashSet<Codon> removed) { if (removed.contains(from) || removed.contains(to)) { if (!removed.contains(from)) return path.union(from); if (!removed.contains(to)) return path.union(to); return path; }//from w w w . jav a 2 s . c o m return extendFullPath(path, from, to, intron); }
From source file:com.chap.memo.memoNodes.MemoNode.java
private StepState doStep(boolean preamble, MemoQuery query, MemoNode toCompare, ArrayList<UUID> results, HashSet<UUID> seenNodes, ArrayList<MemoNode> patterns, int topX, HashMap<String, String> arguments) { MemoNode step = query.node;/*from ww w.j a va 2s .c o m*/ //System.out.println("checking node:" + toCompare.getStringValue() + "/" + query.value + "("+preamble+")"); if (!query.match(toCompare)) return new StepState(false, "Node doesn't match.", query, toCompare); if (seenNodes.contains(toCompare.getId())) return new StepState(true, "Loop/Multipath detected", query, toCompare); if (preamble) { for (MemoNode pattern : patterns) { StepState res = doStep(false, MemoQuery.parseQuery(pattern.getChildren().get(0), arguments), toCompare, null, new HashSet<UUID>(), null, 0, arguments); if (res.matched) { results.add(toCompare.getId()); return new StepState(true, "Node matches pattern! Added to result, no need to search deeper.", query, toCompare); } } } seenNodes.add(toCompare.getId()); List<MemoNode> nextPats = step.getChildren(); int toMatchNo = nextPats.size(); if (toMatchNo == 0) return new StepState(true, "End of pattern", query, toCompare); List<UUID> children = toCompare.getChildIds(); if (!preamble && children.size() < toMatchNo) return new StepState(false, "Too little children for pattern", query, toCompare); ArrayList<MemoQuery> queries = new ArrayList<MemoQuery>(toMatchNo); HashSet<MemoQuery> foundQueries = new HashSet<MemoQuery>(toMatchNo); for (MemoNode nextPat : nextPats) { queries.add(MemoQuery.parseQuery(nextPat, arguments)); } MemoQuery[] queryArray = { new MemoQuery() }; queryArray = queries.toArray(queryArray); Arrays.sort(queryArray); for (UUID uuid : children) { MemoNode child = new MemoNode(uuid); for (MemoQuery iQuery : queryArray) { if (foundQueries.contains(iQuery)) continue; StepState res = doStep(preamble, iQuery, child, results, seenNodes, patterns, topX, arguments); if (topX > 0 && results.size() >= topX) return new StepState(true, "TopX results reached, returning!", query, toCompare); if (preamble || !res.isMatched()) continue; //Return on fully matched pattern foundQueries.add(iQuery); if (foundQueries.size() == queryArray.length) return new StepState(true, "Pattern fully matched", query, toCompare); } } if (preamble) return new StepState(true, "preamble return.", query, toCompare); return new StepState(false, "Pattern didn't match entirely.", query, toCompare); }
From source file:edu.ku.brc.af.ui.forms.BaseBusRules.java
/** * @param skipTableNames/* w w w . ja va2 s . com*/ * @param idColName * @param dataClassObj * @return */ protected String[] gatherTableFieldsForDelete(final String[] skipTableNames, final String idColName, final Class<?> dataClassObj) { boolean debug = false; int fieldCnt = 0; Hashtable<String, Vector<String>> fieldHash = new Hashtable<String, Vector<String>>(); HashSet<String> skipHash = new HashSet<String>(); if (skipTableNames != null) { for (String name : skipTableNames) { skipHash.add(name); } } for (DBTableInfo ti : DBTableIdMgr.getInstance().getTables()) { String tblName = ti.getName(); if (!skipHash.contains(tblName)) { if (dataClassObj != null) { for (DBRelationshipInfo ri : ti.getRelationships()) { if (ri.getDataClass() == dataClassObj) { String colName = ri.getColName(); if (StringUtils.isNotEmpty(colName) /*&& !colName.equals(idColName)*/ //I am pretty sure the following condition reproduces the logic in revision prior to 11305, //if skipHash.contains test is removed above. //&& (!skipHash.contains(tblName) || (skipHash.contains(tblName) && !colName.equals(idColName))) ) { Vector<String> fieldList = fieldHash.get(tblName); if (fieldList == null) { fieldList = new Vector<String>(); fieldHash.put(tblName, fieldList); } fieldList.add(ri.getColName()); fieldCnt++; } } } } } } if (debug) { System.out.println("Fields to be checked:"); for (String tableName : fieldHash.keySet()) { System.out.println(" Table:" + tableName + " "); for (String fName : fieldHash.get(tableName)) { System.out.println(" Field:" + fName); } } } int inx = 0; String[] tableFieldNamePairs = new String[fieldCnt * 2]; for (String tableName : fieldHash.keySet()) { for (String fName : fieldHash.get(tableName)) { ///System.out.println("["+tableName+"]["+fName+"]"); tableFieldNamePairs[inx++] = tableName; tableFieldNamePairs[inx++] = fName; } } return tableFieldNamePairs; }
From source file:com.appeligo.search.actions.SearchResults.java
public List<SearchResult> getSearchResults(int startIndex) { initializeStatics();/*from w ww.ja v a 2 s . co m*/ hasMoreResults = false; try { IndexSearcher searcher = null; try { searcher = newIndexSearcher(); IndexReader reader = searcher.getIndexReader(); Query luceneQuery = generateLuceneQuery(searcher); luceneQuery = luceneQuery.rewrite(reader); Hits hits = searcher.search(luceneQuery); usingSuggestedQuery = false; suggestedQuery = null; if ((didYouMeanParser != null) && ((hits.length() < minimumHits) || (calcScore(searcher, getQuery()) < minimumScore))) { if (log.isDebugEnabled()) { log.debug("Need to suggest because either num hits " + hits.length() + " < " + minimumHits + "\n or top hit score " + (hits.length() > 0 ? hits.score(0) : "[NO HITS]") + " < " + minimumScore); } IndexSearcher compositeSearcher = new IndexSearcher(compositeIndexLocation); try { log.debug("calling suggest() with query=" + getQuery() + " and composite index from " + compositeIndexLocation); //Query didYouMean = didYouMeanParser.suggest(getQuery(), compositeSearcher.getIndexReader()); Query suggestedQueries[] = didYouMeanParser.getSuggestions(getQuery(), compositeSearcher.getIndexReader()); TreeSet<Suggestion> suggestions = new TreeSet<Suggestion>(); if (suggestedQueries != null) { for (int i = 0; i < suggestedQueries.length; i++) { log.debug("trying suggested query: " + suggestedQueries[i].toString(defaultField)); String suggestedQueryString = suggestedQueries[i].toString(defaultField); String constrainedQueryString = suggestedQueryString; if (constrainedQueryString.indexOf('"') < 0 && constrainedQueryString.indexOf('\'') < 0) { constrainedQueryString = "\"" + constrainedQueryString + "\"~5"; // proximity/distance query (within 5 words of each other) } Query suggestedLuceneQuery = generateLuceneQuery(constrainedQueryString, searcher); suggestedLuceneQuery = suggestedLuceneQuery.rewrite(reader); Hits suggestedHits = searcher.search(suggestedLuceneQuery); float score = calcScore(suggestedQueryString, suggestedHits); log.debug("========================================="); log.debug("SCORE = " + score); log.debug("========================================="); suggestions.add( new Suggestion(suggestedQueryString, suggestedLuceneQuery, suggestedHits, score, ((i == 0) ? didYouMeanParser.includesOriginal() : false))); log.debug("hits=" + suggestedHits.length() + ", score=" + score); } } Suggestion best = null; if (suggestions.size() > 0) { best = suggestions.last(); } if (best != null && !best.isOriginal()) { suggestedQuery = best.getQueryString(); if (suggestedQuery != null && suggestedQuery.indexOf('+') >= 0 && getQuery().indexOf('+') < 0) { suggestedQuery = suggestedQuery.replaceAll("\\+", ""); } if (hits.length() == 0) { if (best.getHits().length() > 0) { // Requery probably required because we added proximity before String suggestedQueryString = best.getQueryString(); luceneQuery = generateLuceneQuery(suggestedQueryString, searcher); luceneQuery = luceneQuery.rewrite(reader); hits = searcher.search(luceneQuery); //hits = best.getHits(); //luceneQuery = best.getLuceneQuery(); usingSuggestedQuery = true; } } log.debug("DidYouMeanParser suggested " + suggestedQuery); } else { if (best != null && best.isOriginal()) { log.debug("The suggestion was the original query after all"); } log.debug("DidYouMeanParser did not suggest anything"); } } finally { compositeSearcher.close(); } } /* if (hits.length() == 0 && suggestedQuery != null) { // If we didn't find anything at all, go ahead and show them what the suggested query // will give them Query suggestedLuceneQuery = generateLuceneQuery(suggestedQuery, searcher); suggestedLuceneQuery = suggestedLuceneQuery.rewrite(reader); Hits suggestedHits = searcher.search(suggestedLuceneQuery); if (suggestedHits.length() > 0) { hits = suggestedHits; luceneQuery = suggestedLuceneQuery; usingSuggestedQuery = true; } } */ totalHits = hits.length(); //Get the genere matches: try { BitSetFacetHitCounter facetHitCounter = new BitSetFacetHitCounter(); facetHitCounter.setSearcher(searcher); String baseQueryString = (isUsingSuggestedQuery() ? suggestedQuery : query); String quotedQueryString = baseQueryString; if (quotedQueryString.indexOf('"') == -1 && quotedQueryString.indexOf(' ') > -1) { quotedQueryString = "\"" + quotedQueryString + "\""; } facetHitCounter.setBaseQuery(luceneQuery, baseQueryString); List<HitCount> subQueries = new ArrayList<HitCount>(); for (Map.Entry<String, Query> entry : genreQueries.entrySet()) { subQueries.add( new HitCount(entry.getKey(), entry.getValue(), entry.getValue().toString(), 0)); } facetHitCounter.setSubQueries(subQueries); genreCounts = facetHitCounter.getFacetHitCounts(true); whatMatchedCounts = new ArrayList<HitCount>(); whatMatchedCounts .add(new HitCount("Title", getFieldQuery(baseQueryString, "programTitle", searcher), "programTitle:" + quotedQueryString, 0)); whatMatchedCounts.add( new HitCount("Episode Title", getFieldQuery(baseQueryString, "episodeTitle", searcher), "episodeTitle:" + quotedQueryString, 0)); whatMatchedCounts.add( new HitCount("Description", getFieldQuery(baseQueryString, "description", searcher), "description:" + quotedQueryString, 0)); whatMatchedCounts.add(new HitCount("Content", getFieldQuery(baseQueryString, "text", searcher), "text:" + quotedQueryString, 0)); whatMatchedCounts .add(new HitCount("Credits", getFieldQuery(baseQueryString, "credits", searcher), "credits:" + quotedQueryString, 0)); facetHitCounter.setSubQueries(whatMatchedCounts); whatMatchedCounts = facetHitCounter.getFacetHitCounts(true); //Program Count -- Not sure if there is a better way to do this. HashSet<String> programTitles = new HashSet<String>(); programCounts = new ArrayList<HitCount>(); for (int i = 0; i < hits.length() && programCounts.size() < 5; i++) { String title = hits.doc(i).get("programTitle"); if (!programTitles.contains(title)) { String queryTitle = title; queryTitle = QueryParser.escape(title); if (queryTitle.indexOf('"') > -1) { queryTitle.replace("\"", "\\\""); } if (queryTitle.indexOf(' ') > -1) { queryTitle = "\"" + queryTitle + "\""; } programCounts .add(new HitCount(title, getFieldQuery(queryTitle, "programTitle", searcher), "programTitle:" + queryTitle, 0)); programTitles.add(title); } } facetHitCounter.setSubQueries(programCounts); programCounts = facetHitCounter.getFacetHitCounts(false); } catch (Exception e) { e.printStackTrace(); } results = new ArrayList<SearchResult>(); programToSearchResult.clear(); Query userQuery = getContentQuery(query, searcher); userQuery.rewrite(reader); Highlighter highlighter = new Highlighter(new TermFormatter(), new QueryScorer(userQuery, "text")); log.debug("#hits=" + hits.length()); EPGProvider epgProvider = DefaultEpg.getInstance(); boolean missingWebPaths = false; // We added this to the index midstream, so some do and some don't. // Next index rebuild, and they'll all have it. for (int i = 0; i < pageSize && i + startIndex < hits.length(); i++) { if (hits.doc(i + startIndex).get("webPath") == null) { missingWebPaths = true; break; } } Program[] programs = null; if (missingWebPaths) { List<String> programIds = new ArrayList<String>(pageSize); for (int i = 0; i < pageSize && i + startIndex < hits.length(); i++) { programIds.add(hits.doc(i + startIndex).get("programID")); } programs = DefaultEpg.getInstance().getProgramList(programIds); } for (int i = 0; i < pageSize && i + startIndex < hits.length(); i++) { addDocument(hits.doc(i + startIndex), hits.score(i + startIndex), epgProvider, highlighter, analyzer, null, null, (programs == null ? null : programs[i])); } if (results.size() + startIndex < hits.length()) { hasMoreResults = true; } } finally { if (searcher != null) { searcher.close(); } } } catch (IOException e) { log.error("Error searching index", e); } catch (ParseException e) { log.error("Error searching index", e); } return results; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.listener.impl.IndividualDataPropertyStatementProcessor.java
private void processDataprops(EditProcessObject epo) { HashSet<String> deletedDataPropertyURIs = new HashSet<String>(); Map dpm = datapropParameterMap(epo.getRequestParameterMap()); DataPropertyStatementDao dataPropertyStatementDao = (DataPropertyStatementDao) epo.getAdditionalDaoMap() .get("DataPropertyStatement"); Iterator dpmIt = dpm.keySet().iterator(); while (dpmIt.hasNext()) { String key = (String) dpmIt.next(); String[] data = (String[]) dpm.get(key); for (int dataRow = 0; dataRow < data.length; ++dataRow) { String[] keyArg = key.split("_"); String rowId = keyArg[2]; DataPropertyStatement dataPropertyStmt = new DataPropertyStatementImpl(); if (rowId != null) { // dataPropertyStmt = dataPropertyStatementDao.getDataPropertyStatementByURI(rowId); } else dataPropertyStmt = new DataPropertyStatementImpl(); try { Map beanParamMap = FormUtils.beanParamMapFromString(keyArg[3]); String dataPropertyURI = (String) beanParamMap.get("DatatypePropertyURI"); if (!deletedDataPropertyURIs.contains(dataPropertyURI)) { deletedDataPropertyURIs.add(dataPropertyURI); dataPropertyStatementDao.deleteDataPropertyStatementsForIndividualByDataProperty( ((Individual) epo.getNewBean()).getURI(), dataPropertyURI); }//w ww. j a va 2s .c o m dataPropertyStmt.setDatapropURI(dataPropertyURI); } catch (Exception e) { log.error("Messed up beanParamMap?"); } dataPropertyStmt.setData(data[dataRow]); Individual individual = null; // need to rethink this if (((Individual) epo.getOriginalBean()).getURI() != null) { individual = (Individual) epo.getOriginalBean(); dataPropertyStmt.setIndividualURI(individual.getURI()); } else { individual = (Individual) epo.getNewBean(); dataPropertyStmt.setIndividualURI(individual.getURI()); } if (dataPropertyStmt.getData().length() > 0 && rowId != null) { DataPropertyDao dataPropertyDao = (DataPropertyDao) epo.getAdditionalDaoMap() .get("DataProperty"); DataProperty dp = dataPropertyDao.getDataPropertyByURI(dataPropertyStmt.getDatapropURI()); if (dp != null) { String rangeDatatypeURI = dataPropertyDao.getRequiredDatatypeURI(individual, dp); if (rangeDatatypeURI != null) { dataPropertyStmt.setDatatypeURI(rangeDatatypeURI); String validationMsg = BasicValidationVTwo .validateAgainstDatatype(dataPropertyStmt.getData(), rangeDatatypeURI); // Since this backend editing system is de facto deprecated, // not worrying about implementing per-field validation if (validationMsg != null) { validationMsg = "'" + dataPropertyStmt.getData() + "'" + " is invalid. " + validationMsg; throw new RuntimeException(validationMsg); } } } dataPropertyStatementDao.insertNewDataPropertyStatement(dataPropertyStmt); } //else if (dataPropertyStmt.getData().length()>0 && rowId != null) { // dataPropertyStatementDao.updateDataPropertyStatement(dataPropertyStmt); //} else if (dataPropertyStmt.getData().length()==0 && rowId != null) { // dataPropertyStatementDao.deleteDataPropertyStatement(dataPropertyStmt); //} } } }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassDaoJena.java
public void getAllSubClassURIs(String classURI, HashSet<String> subtree) { List<String> directSubclasses = getSubClassURIs(classURI); Iterator<String> it = directSubclasses.iterator(); while (it.hasNext()) { String uri = it.next();/*from w w w . ja v a 2 s . co m*/ if (!subtree.contains(uri)) { subtree.add(uri); getAllSubClassURIs(uri, subtree); } } }