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


Java Xeger类代码示例

本文整理汇总了Java中nl.flotsam.xeger.Xeger的典型用法代码示例。如果您正苦于以下问题:Java Xeger类的具体用法?Java Xeger怎么用?Java Xeger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GenerateMatchingTupleHelper

import nl.flotsam.xeger.Xeger; //导入依赖的package包/类
ConstraintResult GenerateMatchingTupleHelper(RegexExpression pred,
			boolean invert) throws FrontendException, ExecException {
		// now we are sure that the expression operators are the roots of the
		// plan

		Object rightConst = null;
		int leftCol = -1;
		
		ConstraintResult ret = new ConstraintResult();

		LogicalExpression lhs = pred.getLhs();
		if (lhs instanceof CastExpression)
			lhs = ((CastExpression) lhs).getExpression();
		// if (!(pred.getLhsOperand() instanceof ProjectExpression &&
		// ((ProjectExpression)
		// pred
		// .getLhsOperand()).getProjection().size() == 1))
		// return; // too hard
		if (!(lhs instanceof ProjectExpression))
			return ret;
		//leftCol = ((ProjectExpression) lhs).getColNum();
//		LogicalFieldSchema lfs = schema.getFieldSubNameMatch(((ProjectExpression)lhs).getFieldSchema().alias);
//		if ( lfs != null) {
//			leftCol = schema.getFields().indexOf(lfs);
//  		} else
//  			return ret;
		
		leftCol = extr.extractPosition(schema, ((ProjectExpression)lhs).getFieldSchema().alias);
		if(leftCol == -1)
			return ret;
		
		if (!(pred.getRhs() instanceof ConstantExpression))
			return ret;

		rightConst = ((ConstantExpression) (pred.getRhs())).getValue();

		
		Xeger generator = new Xeger((String) rightConst);
		String text = generator.generate();
		// now we try to change some nulls to constants
		if (invert)
			tOut.set(leftCol, text + "edu.umass.cs.pig");
		else
			tOut.set(leftCol, text);
		ret = new ConstraintResult(CntrTruth.toCntrTruth(invert));
		return ret;
	}
 
开发者ID:kaituo,项目名称:sedge,代码行数:48,代码来源:ConstraintSolver.java

示例2: test

import nl.flotsam.xeger.Xeger; //导入依赖的package包/类
@Test
public void test() {

    // String regex = "[ab]{4,6}c";
    String regex = "(regular|tonic)(ly)?";
    Xeger generator = new Xeger(regex);
    String result = generator.generate();
    assertTrue(result.matches(regex));

    // bruteforce
    Set<String> generated = new HashSet<>();
    for (int i = 0; i < 100000; i++) {
        generated.add(generator.generate());
    }
    for (String g : generated) {
        System.out.println(g);
    }
}
 
开发者ID:sherlok,项目名称:ruta-ontologies,代码行数:19,代码来源:RoboExpanderTest.java

示例3: expand

import nl.flotsam.xeger.Xeger; //导入依赖的package包/类
public static Set<String> expand(String regex) {
    Xeger generator = new Xeger(regex);

    Set<String> generated = new HashSet<>();
    for (int i = 0; i < 10000; i++) { // bruteforce
        generated.add(generator.generate());
    }
    return generated;
}
 
开发者ID:sherlok,项目名称:ruta-ontologies,代码行数:10,代码来源:RoboExpander.java

示例4: GenerateMatchingTupleHelper

import nl.flotsam.xeger.Xeger; //导入依赖的package包/类
ConstraintResultCoral GenerateMatchingTupleHelper(RegexExpression pred,
			boolean invert) throws FrontendException, ExecException {
		// now we are sure that the expression operators are the roots of the
		// plan

		Object rightConst = null;
		int leftCol = -1;
		
		ConstraintResultCoral ret = new ConstraintResultCoral();

		LogicalExpression lhs = pred.getLhs();
		if (lhs instanceof CastExpression)
			lhs = ((CastExpression) lhs).getExpression();
		// if (!(pred.getLhsOperand() instanceof ProjectExpression &&
		// ((ProjectExpression)
		// pred
		// .getLhsOperand()).getProjection().size() == 1))
		// return; // too hard
		if (!(lhs instanceof ProjectExpression))
			return ret;
		//leftCol = ((ProjectExpression) lhs).getColNum();
//		LogicalFieldSchema lfs = schema.getFieldSubNameMatch(((ProjectExpression)lhs).getFieldSchema().alias);
//		if ( lfs != null) {
//			leftCol = schema.getFields().indexOf(lfs);
//  		} else
//  			return ret;
		
		leftCol = extr.extractPosition(schema, ((ProjectExpression)lhs).getFieldSchema().alias);
		if(leftCol == -1)
			return ret;
		
		if (!(pred.getRhs() instanceof ConstantExpression))
			return ret;

		rightConst = ((ConstantExpression) (pred.getRhs())).getValue();

		
		Xeger generator = new Xeger((String) rightConst);
		String text = generator.generate();
		// now we try to change some nulls to constants
		if (invert)
			tOut.set(leftCol, text + "edu.umass.cs.pig");
		else
			tOut.set(leftCol, text);
		ret = new ConstraintResultCoral(CntrTruth.toCntrTruth(invert));
		return ret;
	}
 
开发者ID:kaituo,项目名称:sedge,代码行数:48,代码来源:ConstraintSolverCoral.java

示例5: makeTraces

import nl.flotsam.xeger.Xeger; //导入依赖的package包/类
public String[] makeTraces(StringTracesMakerCmdParameters params) {
    String regexp = "(" + params.regexps[0] + ")";
    Double avgChrsPerString = 0.0;
    long totalChrs = 0L;
    
    
    // building the intersection of the regular expressions
    for (int i = 1; i < params.regexps.length; i++) {
        regexp += "&(" + params.regexps[i] + ")";
    }
    
    // limiting the vocabulary
    String regexpLimitingTheVocabulary = "";
    for (Character s : params.alphabet) {
        regexpLimitingTheVocabulary += s;
    }
    regexp = "([" + regexpLimitingTheVocabulary + "]*)&" + regexp;

    // limiting the number of characters per string
    if (params.isMinChrsPerStringGiven() || params.isMaxChrsPerStringGiven()) {
        regexp =
                regexp +
                "&(.{" +
                (   params.isMinChrsPerStringGiven()
                    ?   params.printMinChrsPerString()
                    :   "0"
                ) +
                "," +
                (   params.isMaxChrsPerStringGiven()
                    ?   params.printMaxChrsPerString()
                    :   ""
                ) +
                "})";
    }

    // generating random strings
    Xeger generator = new Xeger(regexp);
    String[] testBedArray = new String[params.size.intValue()];

    int zeroPaddingCharsAmount = (int)(Math.ceil(Math.log10(testBedArray.length)));
    if (zeroPaddingCharsAmount < 1)
    	zeroPaddingCharsAmount = 1;

    for (int i = 0; i < testBedArray.length; i++) {
        testBedArray[i] = generator.generate();
        totalChrs += testBedArray[i].length();
        logger.trace(String.format("%0" + zeroPaddingCharsAmount + "d", (i))  + ")\t" + testBedArray[i]);
    }
    
    avgChrsPerString = 1.0 * totalChrs / params.size;

    logger.trace(
        "\n"
        + "[Testbed]"
        + (
              "\n\n"
            + "Regular expression(s) generating the proofs: " + params.printRegExps() + "\n"
            + "(extended: " + regexp + ")\n"
            + "conjunction of " + params.getNumberOfConstraints() + " constraint(s)" + "\n"
            + "over " + params.size + " cases" + "\n"
            + "(length of strings ranging from " + params.printMinChrsPerString()
            + " to " + params.printMaxChrsPerString() + ")\n"
            + "(average length of strings: " + avgChrsPerString + ")\n"
            + "with the alphabet: " + params.printAlphabet()
        ).replaceAll("\n", "\n\t")
    );
    
    if (store(params, testBedArray) && params.logFile != null) {
    	logger.info("Log file stored in: " + params.logFile.getAbsolutePath());
    }
    
    return testBedArray;
}
 
开发者ID:cdc08x,项目名称:MINERful,代码行数:74,代码来源:MinerFulStringTracesMaker.java


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