com.martiansoftware.jsap.JSAPException Java Examples

The following examples show how to use com.martiansoftware.jsap.JSAPException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CardumenApproach.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public CardumenApproach(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade) throws JSAPException {
	super(mutatorExecutor, projFacade);
	// Default configuration of Cardumen:
	ConfigurationProperties.setProperty("cleantemplates", "true");

	if (!ConfigurationProperties.hasProperty(ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier)) {

		if (ConfigurationProperties.getPropertyBool("probabilistictransformation")) {
			ConfigurationProperties.setProperty(ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier,
					"name-probability-based");
		} else
			ConfigurationProperties.setProperty(ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier,
					"random-variable-replacement");
	}

	ConfigurationProperties.setProperty(ExtensionPoints.TARGET_CODE_PROCESSOR.identifier, "expression");
	ConfigurationProperties.setProperty(ExtensionPoints.OPERATORS_SPACE.identifier, "r-expression");
	setPropertyIfNotDefined(ExtensionPoints.INGREDIENT_SEARCH_STRATEGY.identifier, "name-probability-based");

}
 
Example #2
Source File: DeepRepairEngine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void loadIngredientPool() throws JSAPException, Exception {

	List<TargetElementProcessor<?>> ingredientProcessors = this.getTargetElementProcessors();

	// The ingredients for build the patches
	String scope = ConfigurationProperties.properties.getProperty("scope");
	CtLocationIngredientSpace ingredientspace = null;
	if ("global".equals(scope)) {
		ingredientspace = (new CtGlobalIngredientScope(ingredientProcessors));
	} else if ("package".equals(scope)) {
		ingredientspace = (new CtPackageIngredientScope(ingredientProcessors));
	} else if ("local".equals(scope)) {
		ingredientspace = (new CtClassIngredientSpace(ingredientProcessors));
	} else {
		ingredientspace = (CtLocationIngredientSpace) PlugInLoader.loadPlugin(
				ExtensionPoints.INGREDIENT_STRATEGY_SCOPE, new Class[] { List.class },
				new Object[] { ingredientProcessors });

	}
	this.setIngredientPool(ingredientspace);
}
 
Example #3
Source File: DeepRepairExhausitiveCloneEngine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public DeepRepairExhausitiveCloneEngine(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade)
		throws JSAPException {
	super(mutatorExecutor, projFacade);

	List<TargetElementProcessor<?>> ingredientProcessors = new ArrayList<TargetElementProcessor<?>>();
	// Fix Space
	ingredientProcessors.add(new SingleStatementFixSpaceProcessor());

	try {
		this.ingredientSpace = (IngredientPool) PlugInLoader.loadPlugin(ExtensionPoints.INGREDIENT_STRATEGY_SCOPE,
				new Class[] { List.class }, new Object[] { ingredientProcessors });

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #4
Source File: GZIPIndexer.java    From BUbiNG with Apache License 2.0 6 votes vote down vote up
public static void main(String[] arg) throws IOException, JSAPException {
	final SimpleJSAP jsap = new SimpleJSAP(GZIPIndexer.class.getName(), "Computes and stores a quasi-succinct index for a compressed archive.",
			new Parameter[] {
				new UnflaggedOption("archive", JSAP.STRING_PARSER, JSAP.REQUIRED, "The name a GZIP's archive."),
				new UnflaggedOption("index", JSAP.STRING_PARSER, JSAP.REQUIRED, "The output (a serialized LongBigList of pointers to the records in the archive) filename."),
			}
	);

	final JSAPResult jsapResult = jsap.parse(arg);
	if (jsap.messagePrinted()) return;

	final FastBufferedInputStream input = new FastBufferedInputStream(new FileInputStream(jsapResult.getString("archive")));
	ProgressLogger pl = new ProgressLogger(LOGGER, 1, TimeUnit.MINUTES, "records");
	pl.start("Scanning...");
	final EliasFanoMonotoneLongBigList list = new EliasFanoMonotoneLongBigList(index(input, pl));
	pl.done();
	BinIO.storeObject(list, jsapResult.getString("index"));
}
 
Example #5
Source File: PatchGenerator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public LiteralsSpace getSpace(ProgramVariant pv) {

		String scope = ConfigurationProperties.properties.getProperty("scope");
		IngredientPoolScope ingScope = IngredientPoolScope.valueOf(scope.toUpperCase());
		if (literalspace == null) {
			try {
				logger.debug("Initializing literal space: scope " + ingScope);
				literalspace = new LiteralsSpace(ingScope);
				literalspace.defineSpace(pv);

			} catch (JSAPException e) {
				e.printStackTrace();
				logger.error(e);
			}
		}
		return literalspace;
	}
 
Example #6
Source File: GramProcessor.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Deprecated
public Map<String, NGrams> calculateByPackage(List<CtType<?>> all) throws JSAPException {

	Map<String, NGrams> result = new HashedMap();
	CodeParserLauncher ingp = new CodeParserLauncher<>(ingredientProcessor);
	int allElements = 0;

	for (CtType<?> ctType : all) {
		NGrams ns = new NGrams();
		CtPackage parent = (CtPackage) ctType.getParent(CtPackage.class);
		if (!result.containsKey(parent.getQualifiedName())) {
			allElements += getNGramsFromCodeElements(parent, ns, ingp);
			result.put(parent.getQualifiedName(), ns);
		}
	}
	logger.debug("allElements " + allElements);
	return result;
}
 
Example #7
Source File: GZIPArchiveWriterTest.java    From BUbiNG with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, JSAPException {

	SimpleJSAP jsap = new SimpleJSAP(GZIPArchiveReader.class.getName(), "Writes some random records on disk.",
		new Parameter[] {
			new Switch("fully", 'f', "fully",
				"Whether to read fully the record (and do a minimal cosnsistency check)."),
			new UnflaggedOption("path", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY,
				"The path to read from."), });

	JSAPResult jsapResult = jsap.parse(args);
	if (jsap.messagePrinted())
	    System.exit(1);

	final boolean fully = jsapResult.getBoolean("fully");
	GZIPArchiveReader gzar = new GZIPArchiveReader(new FileInputStream(jsapResult.getString("path")));
	for (;;) {
	    ReadEntry e = gzar.getEntry();
	    if (e == null)
		break;
	    InputStream inflater = e.lazyInflater.get();
	    if (fully)
		ByteStreams.toByteArray(inflater);
	    e.lazyInflater.consume();
	    System.out.println(e);
	}
    }
 
Example #8
Source File: BuildAnalyzerLauncher.java    From repairnator with MIT License 5 votes vote down vote up
private BuildAnalyzerLauncher(String[] args) throws JSAPException {
    JSAP jsap = this.defineArgs();
    JSAPResult arguments = jsap.parse(args);
    LauncherUtils.checkArguments(jsap, arguments, LauncherType.DOCKERPOOL);

    this.initConfig(arguments);
    this.initSerializerEngines();
    this.initNotifiers();
}
 
Example #9
Source File: ExhaustiveIngredientBasedEngine.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ExhaustiveIngredientBasedEngine(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade)
		throws JSAPException {
	super(mutatorExecutor, projFacade);
	ConfigurationProperties.properties.setProperty(ExtensionPoints.TARGET_CODE_PROCESSOR.identifier, "statements");
	ConfigurationProperties.properties.setProperty(ExtensionPoints.OPERATORS_SPACE.identifier, "irr-statements");
	ConfigurationProperties.properties.setProperty(ExtensionPoints.SUSPICIOUS_NAVIGATION.identifier,
			SuspiciousNavigationValues.INORDER.toString());
}
 
Example #10
Source File: TOSBRApproach.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public TOSBRApproach(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade) throws JSAPException {
	super(mutatorExecutor, projFacade);
	if (!ConfigurationProperties.hasProperty(ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier)) {
		ConfigurationProperties.setProperty(ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier,
				"random-variable-replacement");
	}
}
 
Example #11
Source File: CheckBranchLauncher.java    From repairnator with MIT License 5 votes vote down vote up
private CheckBranchLauncher(String[] args) throws JSAPException {
    JSAP jsap = this.defineArgs();
    JSAPResult arguments = jsap.parse(args);
    LauncherUtils.checkArguments(jsap, arguments, LauncherType.CHECKBRANCHES);

    this.initConfig(arguments);
    this.initNotifiers();
}
 
Example #12
Source File: BranchLauncher.java    From repairnator with MIT License 5 votes vote down vote up
public static void main(String[] args) throws JSAPException {
	JSAP jsap = defineBasicArgs();
	JSAPResult jsapResult = jsap.parse(args);
	
	MainProcess mainProcess = getMainProcess(jsap,args);
	mainProcess.run();
}
 
Example #13
Source File: CatEFGraphsTest.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testWrongBound() throws IOException, JSAPException {
	// (0,1) (0,2) (0,3) (1,7)
	ImmutableGraph graph1 = new XImmutableGraph(ImmutableGraph.wrap(new ArrayListMutableGraph(8, new int[][] { { 0, 1 }, { 0, 2 }, { 0, 3 }, { 1, 7 } }).immutableView()), 4);
	// (4,2) (4,3) (7,4) (7,6)
	ImmutableGraph graph2 = new XImmutableGraph(ImmutableGraph.wrap(new ArrayListMutableGraph(8, new int[][] { { 0, 2 }, { 0, 3 }, { 3, 4 }, { 3, 6 } }).immutableView()), 4);
	File ef1 = new File(dir, "graph1.ef");
	EFGraph.store(graph1, 10, ef1.getAbsolutePath(), null);
	File ef2 = new File(dir, "graph2.ef");
	EFGraph.store(graph2, 8, ef2.getAbsolutePath(), null);
	File result = new File(dir, "result-ef"); result.delete();
	CatEFGraphs.main(new String[] { "-m", result.getAbsolutePath(), ef1.getAbsolutePath(), ef2.getAbsolutePath() });
}
 
Example #14
Source File: Launcher.java    From repairnator with MIT License 5 votes vote down vote up
public static void main(String[] args) throws JSAPException{
    JSAP jsap = defineBasicArgs();
    JSAPResult jsapResult = jsap.parse(args); 
    String choice = jsapResult.getString("launcherChoice");

    if (choice.equals("OLD") ) {
        launcher = new LegacyLauncher(args);
    } else {
        launcher = new BranchLauncher(args);
    }
    RepairnatorConfig.getInstance().setSonarRules(removeDuplicatesInArray(jsapResult.getString("sonarRules").split(",")));
    launcher.launch();
}
 
Example #15
Source File: CodeParserLauncher.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param processors
 * @throws JSAPException
 */
public CodeParserLauncher(List<TargetElementProcessor<?>> processors) throws JSAPException {
	this();
	for (TargetElementProcessor<?> abstractFixSpaceProcessor : processors) {
		processing.addProcessor(abstractFixSpaceProcessor.getClass().getName() );
	}
}
 
Example #16
Source File: jMutRepairExhaustive.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public jMutRepairExhaustive(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade)
		throws JSAPException {
	super(mutatorExecutor, projFacade);
	ConfigurationProperties.properties.setProperty("regressionforfaultlocalization", "true");
	ConfigurationProperties.properties.setProperty("population", "1");
	setPropertyIfNotDefined(ExtensionPoints.OPERATORS_SPACE.identifier, "mutationspace");
	setPropertyIfNotDefined(ExtensionPoints.TARGET_CODE_PROCESSOR.identifier,
			"if-conditions" + File.pathSeparator + "return-op-mutation");
}
 
Example #17
Source File: HttpResponseWarcRecordTest.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public static void main(String[] arg) throws JSAPException, URISyntaxException, NoSuchAlgorithmException, ClientProtocolException, IOException, InterruptedException, ConfigurationException, IllegalArgumentException, ClassNotFoundException {

		SimpleJSAP jsap = new SimpleJSAP(HttpResponseWarcRecordTest.class.getName(), "Outputs an URL (given as argument) as the UncompressedWarcWriter would do",
			new Parameter[] {
				new UnflaggedOption("url", JSAP.STRING_PARSER, JSAP.REQUIRED, "The url of the page."),
			});

		JSAPResult jsapResult = jsap.parse(arg);
		if (jsap.messagePrinted()) System.exit(1);

		final String url = jsapResult.getString("url");

		final URI uri = new URI(url);
		final WarcWriter writer = new UncompressedWarcWriter(System.out);

		// Setup FetchData
		final RuntimeConfiguration testConfiguration = Helpers.getTestConfiguration(null);
		final HttpClient httpClient = FetchDataTest.getHttpClient(null, false);
		final FetchData fetchData = new FetchData(testConfiguration);

		fetchData.fetch(uri, httpClient, null, null, false);
		final HttpResponseWarcRecord record = new HttpResponseWarcRecord(uri, fetchData.response());
		writer.write(record);
		fetchData.close();
		System.out.println(record);

		writer.close();
	}
 
Example #18
Source File: Cardumen1HApproach.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public Cardumen1HApproach(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade) throws JSAPException {

		super(mutatorExecutor, projFacade);

		ConfigurationProperties.setProperty(ExtensionPoints.TARGET_CODE_PROCESSOR.identifier, "expression");
		ConfigurationProperties.setProperty(ExtensionPoints.OPERATORS_SPACE.identifier, "r-expression");

		ConfigurationProperties.setProperty("nrPlaceholders", "1");
		ConfigurationProperties.setProperty("excludevariableplaceholder", "false");
		ConfigurationProperties.setProperty("excludeliteralplaceholder", "true");
		ConfigurationProperties.setProperty("excludeinvocationplaceholder", "true");
		ConfigurationProperties.setProperty("excludevarliteralplaceholder", "true");

	}
 
Example #19
Source File: JKaliEngine.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public JKaliEngine(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade) throws JSAPException {
	super(mutatorExecutor, projFacade);
	ConfigurationProperties.properties.setProperty("regressionforfaultlocalization", "true");
	ConfigurationProperties.properties.setProperty("population", "1");
	setPropertyIfNotDefined(ExtensionPoints.OPERATORS_SPACE.identifier, "suppression");
	setPropertyIfNotDefined(ExtensionPoints.TARGET_CODE_PROCESSOR.identifier, "statements");
}
 
Example #20
Source File: MultiMetaEvalTOSApproach.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultiMetaEvalTOSApproach(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade)
		throws JSAPException {
	super(mutatorExecutor, projFacade);
	MAX_GENERATIONS = ConfigurationProperties.getPropertyInt("maxGeneration");
	this.operatorSpace = new OperatorSpace();
	loadPredictor();
}
 
Example #21
Source File: CardumenExhaustiveApproach.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void loadIngredientPool() throws JSAPException, Exception {
	List<TargetElementProcessor<?>> ingredientProcessors = this.getTargetElementProcessors();
	ExpressionTypeIngredientSpace ingredientspace = ((ConfigurationProperties.getPropertyBool("uniformreplacement"))
			? new ExpressionClassTypeIngredientSpace(ingredientProcessors)
			: new ExpressionTypeIngredientSpace(ingredientProcessors));
	String scope = ConfigurationProperties.getProperty(ExtensionPoints.INGREDIENT_STRATEGY_SCOPE.identifier);
	if (scope != null) {
		ingredientspace.scope = IngredientPoolScope.valueOf(scope.toUpperCase());
	}
	this.setIngredientPool(ingredientspace);
}
 
Example #22
Source File: RTLauncher.java    From repairnator with MIT License 5 votes vote down vote up
public static void main(String[] args) throws JSAPException {
    RTLauncher rtLauncher = new RTLauncher(args);
    /* If scanner mode is RTSCanner */
    rtLauncher.initAndRunRTScanner();
    /* If scanner mode is BuildRainer */
    /* Create and connect BuildRainer */
}
 
Example #23
Source File: PermutedFrontCodedStringList.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, ClassNotFoundException, JSAPException {

		SimpleJSAP jsap = new SimpleJSAP( PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and permutation",  
				new Parameter[] {
					new Switch( "invert", 'i', "invert", "Invert permutation before creating the permuted list." ),
					new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list." ),
					new UnflaggedOption( "permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list." ),
					new UnflaggedOption( "permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list." ),
			} );

		JSAPResult jsapResult = jsap.parse( arg ); 
		if ( jsap.messagePrinted() ) return;
		
		int[] basePermutation =  BinIO.loadInts( jsapResult.getString( "permutation" ) ), permutation;
		if ( jsapResult.getBoolean( "invert" ) ) {
			int i = basePermutation.length;
			permutation = new int[ i ];
			while( i-- != 0 ) permutation[ basePermutation[ i ] ] = i;
		}
		else permutation = basePermutation;
		
		basePermutation = null;
		
		BinIO.storeObject( 
				new PermutedFrontCodedStringList( (FrontCodedStringList)BinIO.loadObject( jsapResult.getString( "list" ) ), permutation ), 
				jsapResult.getString( "permutedList" ) 
		);
	}
 
Example #24
Source File: ShiftAddXorSignedStringMap.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main( final String[] arg ) throws NoSuchMethodException, IOException, JSAPException, ClassNotFoundException {

	final SimpleJSAP jsap = new SimpleJSAP( ShiftAddXorSignedStringMap.class.getName(), "Builds a shift-add-xor signed string map by reading a newline-separated list of strings and a function built on the same list of strings.",
			new Parameter[] {
		new FlaggedOption( "bufferSize", JSAP.INTSIZE_PARSER, "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read strings." ),
		new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The string file encoding." ),
		new Switch( "zipped", 'z', "zipped", "The string list is compressed in gzip format." ),
		new FlaggedOption( "width", JSAP.INTEGER_PARSER, Integer.toString( Integer.SIZE ), JSAP.NOT_REQUIRED, 'w', "width", "The signature width in bits." ),
		new UnflaggedOption( "function", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the function to be signed." ),
		new UnflaggedOption( "map", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the resulting serialised signed string map." ),
		new UnflaggedOption( "stringFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "Read strings from this file instead of standard input." ),
	});

	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;

	final int bufferSize = jsapResult.getInt( "bufferSize" );
	final String functionName = jsapResult.getString( "function" );
	final String mapName = jsapResult.getString( "map" );
	final String stringFile = jsapResult.getString( "stringFile" );
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );
	final int width = jsapResult.getInt( "width" );
	final boolean zipped = jsapResult.getBoolean( "zipped" );

	final InputStream inputStream = stringFile != null ? new FileInputStream( stringFile ) : System.in;
	final Iterator<MutableString> iterator = new LineIterator( new FastBufferedReader( new InputStreamReader( zipped ? new GZIPInputStream( inputStream ) : inputStream, encoding ), bufferSize ) );
	final Object2LongFunction<CharSequence> function = (Object2LongFunction<CharSequence>)BinIO.loadObject( functionName );
	LOGGER.info( "Signing..." );
	BinIO.storeObject( new ShiftAddXorSignedStringMap( iterator, function, width ), mapName );
	LOGGER.info( "Completed." );
}
 
Example #25
Source File: TOSBRApproachExha.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public TOSBRApproachExha(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade) throws JSAPException {
	super(mutatorExecutor, projFacade);

	if (!ConfigurationProperties.hasProperty(ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier)) {
		ConfigurationProperties.setProperty(ExtensionPoints.INGREDIENT_TRANSFORM_STRATEGY.identifier,
				"random-variable-replacement");
	}

}
 
Example #26
Source File: FrontCodedStringList.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, JSAPException, NoSuchMethodException {
	
	final SimpleJSAP jsap = new SimpleJSAP( FrontCodedStringList.class.getName(), "Builds a front-coded string list reading from standard input a newline-separated ordered list of terms.",
			new Parameter[] {
				new FlaggedOption( "bufferSize", IntSizeStringParser.getParser(), "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read terms." ),
				new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding." ),
				new FlaggedOption( "ratio", IntSizeStringParser.getParser(), "4", JSAP.NOT_REQUIRED, 'r',  "ratio", "The compression ratio." ),
				new Switch( "utf8", 'u', "utf8", "Store the strings as UTF-8 byte arrays." ),
				new Switch( "zipped", 'z', "zipped", "The term list is compressed in gzip format." ),
				new UnflaggedOption( "frontCodedList", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised front-coded list." )
	});
	
	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;
	
	final int bufferSize = jsapResult.getInt( "bufferSize" );
	final int ratio = jsapResult.getInt( "ratio" );
	final boolean utf8 = jsapResult.getBoolean( "utf8" );
	final boolean zipped = jsapResult.getBoolean( "zipped" );
	final String listName = jsapResult.getString( "frontCodedList" );
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );
	
	final ProgressLogger pl = new ProgressLogger();
	pl.itemsName = "words";
	pl.start( "Reading words..." );
	final FrontCodedStringList frontCodedStringList = new FrontCodedStringList( new LineIterator( new FastBufferedReader( 
			new InputStreamReader( zipped ? new GZIPInputStream( System.in ) : System.in, encoding ), bufferSize ), pl ), ratio, utf8 );
	pl.done();

	System.err.print( "Writing to file..." );
	BinIO.storeObject( frontCodedStringList, listName );
	System.err.println( " done." );
}
 
Example #27
Source File: TernaryIntervalSearchTree.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, JSAPException, NoSuchMethodException {

		final SimpleJSAP jsap = new SimpleJSAP( TernaryIntervalSearchTree.class.getName(), "Builds a ternary interval search tree reading from standard input a newline-separated list of terms.",
			new Parameter[] {
				new FlaggedOption( "bufferSize", JSAP.INTSIZE_PARSER, "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read terms." ),
				new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding." ),
				new UnflaggedOption( "tree", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised tree." )
		});

		JSAPResult jsapResult = jsap.parse( arg );
		if ( jsap.messagePrinted() ) return;

		final TernaryIntervalSearchTree tree = new TernaryIntervalSearchTree();
		
		MutableString term = new MutableString();
		final ProgressLogger pl = new ProgressLogger();
		pl.itemsName = "terms";
		final FastBufferedReader terms = new FastBufferedReader( new InputStreamReader( System.in, (Charset)jsapResult.getObject( "encoding" ) ), jsapResult.getInt( "bufferSize" ) );
				
		pl.start( "Reading terms..." );

		while( terms.readLine( term ) != null ) {
			pl.update();
			tree.add( term );
		}

		pl.done();

		BinIO.storeObject( tree, jsapResult.getString( "tree" ) );
	}
 
Example #28
Source File: LiterallySignedStringMap.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main( final String[] arg ) throws IOException, JSAPException, ClassNotFoundException, SecurityException, NoSuchMethodException {

	final SimpleJSAP jsap = new SimpleJSAP( LiterallySignedStringMap.class.getName(), "Builds a shift-add-xor signed string map by reading a newline-separated list of strings and a function built on the same list of strings.",
			new Parameter[] {
		new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The string file encoding." ),
		new Switch( "zipped", 'z', "zipped", "The string list is compressed in gzip format." ),
		new Switch( "text", 't', "text", "The string list actually a text file, with one string per line." ),
		new UnflaggedOption( "function", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the function to be signed." ),
		new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the serialised list of strings, or of a text file containing a list of strings, if -t is specified." ),
		new UnflaggedOption( "map", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the resulting map." ),
	});

	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;

	final String functionName = jsapResult.getString( "function" );
	final String listName = jsapResult.getString( "list" );
	final String mapName = jsapResult.getString( "map" );

	
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );
	final boolean zipped = jsapResult.getBoolean( "zipped" );
	final boolean text = jsapResult.getBoolean( "text" );
	
	ObjectList<MutableString> list = text ? new FileLinesCollection( listName, encoding.toString(), zipped ).allLines() : (ObjectList)BinIO.loadObject( listName );
	
	LOGGER.info( "Signing..." );
	BinIO.storeObject( new LiterallySignedStringMap( (Object2LongFunction)BinIO.loadObject( functionName ), list ), mapName );
	LOGGER.info( "Completed." );
}
 
Example #29
Source File: BloomFilter.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, JSAPException, NoSuchMethodException {
	
	final SimpleJSAP jsap = new SimpleJSAP( BloomFilter.class.getName(), "Creates a Bloom filter reading from standard input a newline-separated list of terms.",
			new Parameter[] {
				new FlaggedOption( "bufferSize", IntSizeStringParser.getParser(), "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read terms." ),
				new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding." ),
				new UnflaggedOption( "bloomFilter", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised front-coded list." ),
				new UnflaggedOption( "size", JSAP.INTSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The size of the filter (i.e., the expected number of elements in the filter; usually, the number of terms)." ),
				new UnflaggedOption( "precision", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The precision of the filter." )
	});
	
	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;
	
	final int bufferSize = jsapResult.getInt( "bufferSize" );
	final String filterName = jsapResult.getString( "bloomFilter" );
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );

	BloomFilter filter = new BloomFilter( jsapResult.getInt( "size" ), jsapResult.getInt( "precision" ) );
	final ProgressLogger pl = new ProgressLogger();
	pl.itemsName = "terms";
	pl.start( "Reading terms..." );
	MutableString s = new MutableString();
	FastBufferedReader reader = new FastBufferedReader( new InputStreamReader( System.in, encoding ), bufferSize );
	while( reader.readLine( s ) != null ) { 
		filter.add( s );
		pl.lightUpdate();
	}
	pl.done();

	BinIO.storeObject( filter, filterName );
}
 
Example #30
Source File: CardumenApproach.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void loadIngredientPool() throws JSAPException, Exception {
	List<TargetElementProcessor<?>> ingredientProcessors = this.getTargetElementProcessors();
	ExpressionTypeIngredientSpace ingredientspace = ((ConfigurationProperties.getPropertyBool("uniformreplacement"))
			? new ExpressionClassTypeIngredientSpace(ingredientProcessors)
			: new ExpressionTypeIngredientSpace(ingredientProcessors));
	String scope = ConfigurationProperties.getProperty(ExtensionPoints.INGREDIENT_STRATEGY_SCOPE.identifier);
	if (scope != null) {
		ingredientspace.scope = IngredientPoolScope.valueOf(scope.toUpperCase());
	}
	this.setIngredientPool(ingredientspace);
}