/** * parse comma delimited int * @param src * @return int[] */ public static int[] parseCommaDelimitedInts(String src) { final String[] parts = parseCommaDelimitedString(src); if (parts.length == 0) return new int[0]; int[] rtr = new int[parts.length]; for(int i=0;i<parts.length;i++) rtr[i] = Integer.parseInt(parts[i]); return rtr; } /**
/** * parse comma delimited int * @param src * @return int[] */ public static int[] parseCommaDelimitedInts(String src) { final String[] parts = parseCommaDelimitedString(src); if (parts.length == 0) return new int[0]; int[] rtr = new int[parts.length]; for(int i=0;i<parts.length;i++) rtr[i] = Integer.parseInt(parts[i]); return rtr; } /**
public static int getFieldId(Index index, String structureName, String fieldName) { if (fieldName == null) return -1; String[] fieldNames = ArrayUtils.parseCommaDelimitedString(index.getIndexProperty("index.direct.fields.names", "")); int i=-1; for(String f : fieldNames) { i++; if (f.equals(fieldName)) return i; } return -1; }
public static int getFieldId(Index index, String structureName, String fieldName) { if (fieldName == null) return -1; String[] fieldNames = ArrayUtils.parseCommaDelimitedString(index.getIndexProperty("index.direct.fields.names", "")); int i=-1; for(String f : fieldNames) { i++; if (f.equals(fieldName)) return i; } return -1; }
/** we may have been specified some files to cache immediately */ protected static void initialise_static_cache() { String[] filesToCache = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("files.to.cache", "")); for (String filename : filesToCache) { try{ System.err.println("Caching file " + filename); cacheFile(filename); } catch (Exception e) { System.err.println("Could not cache file "+ filename +" because " + e); e.printStackTrace(); } } }
/** we may have been specified some files to cache immediately */ protected static void initialise_static_cache() { String[] filesToCache = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("files.to.cache", "")); for (String filename : filesToCache) { try{ System.err.println("Caching file " + filename); cacheFile(filename); } catch (Exception e) { System.err.println("Could not cache file "+ filename +" because " + e); e.printStackTrace(); } } }
public static IntegerCodec loadCodec(String className) throws Exception { String[] params = null; if (className.matches(".+\\(.+\\)$")) { String[] tmp = className.split("\\("); className = tmp[0]; params = ArrayUtils.parseCommaDelimitedString(tmp[1].replaceAll("\\)$", "")); } if (! className.contains(".")) { className = GammaCodec.class.getPackage().toString().replaceFirst("package ", "") +'.' + className; } Class<? extends IntegerCodec> c = ApplicationSetup.getClass(className).asSubclass(IntegerCodec.class); IntegerCodec factory = null; if (params != null) { factory = c.getConstructor(String[].class).newInstance((Object) params); } else { factory = c.newInstance(); } return factory; }
public static IntegerCodec loadCodec(String className) throws Exception { String[] params = null; if (className.matches(".+\\(.+\\)$")) { String[] tmp = className.split("\\("); className = tmp[0]; params = ArrayUtils.parseCommaDelimitedString(tmp[1].replaceAll("\\)$", "")); } if (! className.contains(".")) { className = GammaCodec.class.getPackage().toString().replaceFirst("package ", "") +'.' + className; } Class<? extends IntegerCodec> c = ApplicationSetup.getClass(className).asSubclass(IntegerCodec.class); IntegerCodec factory = null; if (params != null) { factory = c.getConstructor(String[].class).newInstance((Object) params); } else { factory = c.newInstance(); } return factory; }
/** * Constructs an instance of TRECQuery, * that reads and stores all the queries from * the files defined in the trec.topics property. */ public TRECQuery() { //this(ApplicationSetup.getProperty("trec.topics", null)); try { String files[] = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("trec.topics", "")); assert files.length > 0; Vector<String> vecStringQueries = new Vector<String>(); Vector<String> vecStringQueryIDs = new Vector<String>(); Vector<String> vecStringFiles = new Vector<String>(); for (int i=0; i<files.length;i++) { if (this.extractQuery(files[i], vecStringQueries, vecStringQueryIDs)) { vecStringFiles.add(files[i]); } } this.topicFiles = vecStringQueries.toArray(new String[0]); this.queries = vecStringQueries.toArray(new String[0]); this.query_ids = vecStringQueryIDs.toArray(new String[0]); this.index = 0; } catch (Exception ioe) { logger.error("Problem getting trec.topics property:", ioe); return; } }
public MemoryMetaIndex() { this( ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("indexer.meta.forward.keys", "")), ArrayUtils.parseCommaDelimitedInts(ApplicationSetup.getProperty("indexer.meta.forward.keylens", "")), ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("indexer.meta.reverse.keys", "")) ); }
/** * Constructs an instance of TRECQuery, * that reads and stores all the queries from * the files defined in the trec.topics property. */ public TRECQuery() { //this(ApplicationSetup.getProperty("trec.topics", null)); try { String files[] = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("trec.topics", "")); assert files.length > 0; Vector<String> vecStringQueries = new Vector<String>(); Vector<String> vecStringQueryIDs = new Vector<String>(); Vector<String> vecStringFiles = new Vector<String>(); for (int i=0; i<files.length;i++) { if (this.extractQuery(files[i], vecStringQueries, vecStringQueryIDs)) { vecStringFiles.add(files[i]); } } this.topicFiles = vecStringQueries.toArray(new String[0]); this.queries = vecStringQueries.toArray(new String[0]); this.query_ids = vecStringQueryIDs.toArray(new String[0]); this.index = 0; } catch (Exception ioe) { logger.error("Problem getting trec.topics property:", ioe); return; } }
/** * * A default constructor that creates an instance of the class * and loads in memory the relevance assessments from the files * that are specified in the file specified by the property * TREC_QRELS. */ public TRECQrelsInMemory(){ try { String files[]; files = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("trec.qrels", "")); if (files.length == 0) throw new IllegalArgumentException("No relevance assessments specified in property trec.qrels"); fqrels = new File[files.length]; for (int i=0; i<files.length;i++) fqrels[i] = new File(files[i]); this.loadQrelsFile(); } catch (Exception ioe) { logger.error("Problem loading relevance assessments from property trec.qrels :", ioe); return; } } /**
/** * * A default constructor that creates an instance of the class * and loads in memory the relevance assessments from the files * that are specified in the file specified by the property * TREC_QRELS. */ public TRECQrelsInMemory(){ try { String files[]; files = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("trec.qrels", "")); if (files.length == 0) throw new IllegalArgumentException("No relevance assessments specified in property trec.qrels"); fqrels = new File[files.length]; for (int i=0; i<files.length;i++) fqrels[i] = new File(files[i]); this.loadQrelsFile(); } catch (Exception ioe) { logger.error("Problem loading relevance assessments from property trec.qrels :", ioe); return; } } /**
@Test public void testParseCommaDelimitedStrings() throws Exception { assertTrue(Arrays.equals(new String[0], ArrayUtils.parseCommaDelimitedString(""))); assertTrue(Arrays.equals(new String[0], ArrayUtils.parseCommaDelimitedString(" "))); assertTrue(Arrays.equals(new String[]{"1"}, ArrayUtils.parseCommaDelimitedString("1"))); assertTrue(Arrays.equals(new String[]{"1"}, ArrayUtils.parseCommaDelimitedString(" 1"))); assertTrue(Arrays.equals(new String[]{"1"}, ArrayUtils.parseCommaDelimitedString("1 "))); assertTrue(Arrays.equals(new String[]{"1"}, ArrayUtils.parseCommaDelimitedString(" 1 "))); assertTrue(Arrays.equals(new String[]{"1","2"}, ArrayUtils.parseCommaDelimitedString("1,2"))); assertTrue(Arrays.equals(new String[]{"1","2"}, ArrayUtils.parseCommaDelimitedString("1 ,2"))); assertTrue(Arrays.equals(new String[]{"1","2"}, ArrayUtils.parseCommaDelimitedString("1, 2"))); assertTrue(Arrays.equals(new String[]{"1","2"}, ArrayUtils.parseCommaDelimitedString("1 , 2"))); assertTrue(Arrays.equals(new String[]{"12","256"}, ArrayUtils.parseCommaDelimitedString("12,256"))); }
/** * Get the query parser that is being used. * * @return The query parser that is being used. */ protected QuerySource getQueryParser() { String[] topicsFiles = null; QuerySource rtr = null; try { Class<? extends QuerySource> queryingClass = ApplicationSetup.getClass( getTopicsParser().indexOf('.') > 0 ? getTopicsParser() : "org.terrier.structures." + getTopicsParser()) .asSubclass(QuerySource.class); if ((topicsFiles = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("trec.topics", ""))).length > 0) { //condensing the following code any further results in warnings Class<?>[] types = { String[].class }; Object[] params = { topicsFiles }; rtr = queryingClass.getConstructor(types).newInstance(params); } else { logger.error("Error instantiating topic file. Please set the topic file(s) using trec.topics property" , new IllegalArgumentException()); } // } catch (ClassNotFoundException cnfe) { } catch (Exception e) { logger.error("Error instantiating topic file QuerySource called " + getTopicsParser(), e); } return rtr; }
/** * Get the query parser that is being used. * * @return The query parser that is being used. */ protected QuerySource getQueryParser() { String[] topicsFiles = null; QuerySource rtr = null; try { Class<? extends QuerySource> queryingClass = ApplicationSetup.getClass( getTopicsParser().indexOf('.') > 0 ? getTopicsParser() : "org.terrier.structures." + getTopicsParser()) .asSubclass(QuerySource.class); if ((topicsFiles = ArrayUtils.parseCommaDelimitedString(ApplicationSetup.getProperty("trec.topics", ""))).length > 0) { //condensing the following code any further results in warnings Class<?>[] types = { String[].class }; Object[] params = { topicsFiles }; rtr = queryingClass.getConstructor(types).newInstance(params); } else { logger.error("Error instantiating topic file. Please set the topic file(s) using trec.topics property" , new IllegalArgumentException()); } // } catch (ClassNotFoundException cnfe) { } catch (Exception e) { logger.error("Error instantiating topic file QuerySource called " + getTopicsParser(), e); } return rtr; }
/** * constructor * @param _srcIndex1 * @param _srcIndex2 * @param _destIndex */ public BlockStructureMerger(IndexOnDisk _srcIndex1, IndexOnDisk _srcIndex2, IndexOnDisk _destIndex) { super(_srcIndex1, _srcIndex2, _destIndex); String[] fieldNames = ArrayUtils.parseCommaDelimitedString(srcIndex1.getIndexProperty("index.inverted.fields.names", "")); int blocks = srcIndex1.getIntIndexProperty("index.inverted.blocks", 1); int maxblocks = srcIndex1.getIntIndexProperty("index.inverted.blocks.max", ApplicationSetup.MAX_BLOCKS); compressionDirectConfig = CompressionFactory.getCompressionConfiguration("direct", fieldNames, blocks, maxblocks); compressionInvertedConfig = CompressionFactory.getCompressionConfiguration("inverted", fieldNames, blocks, maxblocks); }
/** * constructor * @param _srcIndex1 * @param _srcIndex2 * @param _destIndex */ public StructureMerger(IndexOnDisk _srcIndex1, IndexOnDisk _srcIndex2, IndexOnDisk _destIndex) { this.srcIndex1 = _srcIndex1; this.srcIndex2 = _srcIndex2; this.destIndex = _destIndex; numberOfDocuments = 0; numberOfPointers = 0; numberOfTerms = 0; final int srcFieldCount1 = srcIndex1.getIntIndexProperty("index.inverted.fields.count", 0); final int srcFieldCount2 = srcIndex2.getIntIndexProperty("index.inverted.fields.count", 0); if (srcFieldCount1 != srcFieldCount2) { throw new Error("FieldCounts in source indices must match"); } String[] fieldNames = ArrayUtils.parseCommaDelimitedString(srcIndex1.getIndexProperty("index.inverted.fields.names", "")); assert srcFieldCount1 == fieldNames.length; fieldCount = srcFieldCount1; compressionDirectConfig = CompressionFactory.getCompressionConfiguration("direct", fieldNames, 0,0); compressionInvertedConfig = CompressionFactory.getCompressionConfiguration("inverted", fieldNames, 0,0); }
ArrayUtils.parseCommaDelimitedString(index.getIndexProperty("index.inverted.fields.names", "")), index.getIntIndexProperty("index.inverted.blocks", 0), index.getIntIndexProperty("index.inverted.blocks.max", 0));
ArrayUtils.parseCommaDelimitedString(index.getIndexProperty("index.inverted.fields.names", "")), index.getIntIndexProperty("index.inverted.blocks", 0), index.getIntIndexProperty("index.inverted.blocks.max", 0));