Search in sources :

Example 21 with Hashtable

use of java.util.Hashtable in project lucida by claritylab.

the class ScoreCombinationFilter method apply.

/**
	 * Filters an array of <code>Result</code> objects.
	 * 
	 * @param results results to filter
	 * @return filtered results
	 */
public Result[] apply(Result[] results) {
    // all results that pass the filter
    List<Result> filtered = new ArrayList<Result>();
    // sort results by their scores in descending order
    results = (new ScoreSorterFilter()).apply(results);
    // separate factoid answers by extractors
    List<Result> factoids = new ArrayList<Result>();
    Hashtable<String, Hashtable<String, Result>> allExtractors = new Hashtable<String, Hashtable<String, Result>>();
    for (Result result : results) {
        // only merge factoid answers
        if (result.getScore() <= 0 || result.getScore() == Float.POSITIVE_INFINITY) {
            filtered.add(result);
            continue;
        }
        // make sure that answers come from a single extractor
        String[] extractors = result.getExtractionTechniques();
        if (extractors == null || extractors.length != 1) {
            filtered.add(result);
            continue;
        }
        String extractor = extractors[0];
        factoids.add(result);
        Hashtable<String, Result> sameExtractor = allExtractors.get(extractor);
        if (sameExtractor == null) {
            sameExtractor = new Hashtable<String, Result>();
            allExtractors.put(extractor, sameExtractor);
        }
        String norm = StringUtils.normalize(result.getAnswer());
        sameExtractor.put(norm, result);
    }
    // merge answers from different extractors
    String[] extractors = allExtractors.keySet().toArray(new String[allExtractors.size()]);
    Set<String> covered = new HashSet<String>();
    for (Result result : factoids) {
        String norm = StringUtils.normalize(result.getAnswer());
        if (!covered.add(norm))
            continue;
        // get all extractors for the result and the normalized scores
        ArrayList<String> exs = new ArrayList<String>();
        ArrayList<Float> scores = new ArrayList<Float>();
        for (String extractor : extractors) {
            Result r = allExtractors.get(extractor).get(norm);
            if (r != null) {
                exs.add(extractor);
                scores.add(r.getNormScore());
            }
        }
        // set extractors
        result.setExtractionTechniques(exs.toArray(new String[exs.size()]));
        // combine their normalized scores
        float[] scoresA = new float[scores.size()];
        for (int i = 0; i < scoresA.length; i++) scoresA[i] = scores.get(i);
        int totalExtractors = extractors.length;
        float combinedScore = //				combANZ(scoresA, totalExtractors);
        combMNZ(scoresA, totalExtractors);
        //				combCP(scoresA, totalExtractors);
        result.setScore(combinedScore);
        result.setNormScore(combinedScore);
        filtered.add(result);
    }
    return filtered.toArray(new Result[filtered.size()]);
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Result(info.ephyra.search.Result) HashSet(java.util.HashSet)

Example 22 with Hashtable

use of java.util.Hashtable in project lucida by claritylab.

the class TruncationFilter method apply.

/**
	 * Filters an array of <code>Result</code> objects.
	 * 
	 * @param results results to filter
	 * @return filtered results
	 */
public Result[] apply(Result[] results) {
    // all results that pass the filter
    ArrayList<Result> filtered = new ArrayList<Result>();
    // for each extractor, truncated answers and corresponding results
    Hashtable<String, Hashtable<String, Result>> truncated = new Hashtable<String, Hashtable<String, Result>>();
    // sort results by their scores in descending order
    results = (new ScoreSorterFilter()).apply(results);
    for (Result result : results) {
        // only truncate factoid answers
        if (result.getScore() <= 0 || result.getScore() == Float.POSITIVE_INFINITY) {
            filtered.add(result);
            continue;
        }
        // make sure that answers come from a single extractor
        String[] extractors = result.getExtractionTechniques();
        if (extractors == null || extractors.length != 1) {
            filtered.add(result);
            continue;
        }
        String extractor = extractors[0];
        // truncate result
        result = apply(result);
        // merge with similar results from same extractor
        Hashtable<String, Result> truncatedT = truncated.get(extractor);
        if (truncatedT == null) {
            truncatedT = new Hashtable<String, Result>();
            truncated.put(extractor, truncatedT);
        }
        String norm = StringUtils.normalize(result.getAnswer());
        Result similar = truncatedT.get(norm);
        if (similar == null) {
            filtered.add(result);
            truncatedT.put(norm, result);
        } else {
            similar.incScore(result.getScore());
        }
    }
    return filtered.toArray(new Result[filtered.size()]);
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Result(info.ephyra.search.Result)

Example 23 with Hashtable

use of java.util.Hashtable in project lucida by claritylab.

the class ScoreNormalizationFilter method preserveOrderTop.

/**
	 * Calculates the normalization factor of the top answer for each extraction
	 * technique and normalizes the scores with this factor to ensure that the
	 * order suggested by the original scores is preserved.
	 * 
	 * @param results array of <code>Result</code> objects
	 * @return array of <code>Result</code> objects with new normalized scores
	 */
public Result[] preserveOrderTop(Result[] results) {
    // get answers by extractors
    Hashtable<String, ArrayList<Result>> allExtracted = new Hashtable<String, ArrayList<Result>>();
    for (Result result : results) {
        // only factoid answers with 1 extraction technique
        if (result.getScore() <= 0 || result.getScore() == Float.POSITIVE_INFINITY || result.getExtractionTechniques() == null || result.getExtractionTechniques().length != 1)
            continue;
        String extractor = result.getExtractionTechniques()[0];
        ArrayList<Result> extracted = allExtracted.get(extractor);
        if (extracted == null) {
            extracted = new ArrayList<Result>();
            allExtracted.put(extractor, extracted);
        }
        extracted.add(result);
    }
    // normalize answer scores for each extractor
    for (List<Result> extracted : allExtracted.values()) {
        // get 	normalization factor of top answer
        float maxScore = 0;
        float maxNormScore = 0;
        for (Result factoid : extracted) {
            float score = factoid.getScore();
            float normScore = factoid.getNormScore();
            if (score > maxScore) {
                maxScore = score;
                maxNormScore = normScore;
            }
        }
        double topNormFactor = maxNormScore / maxScore;
        // normalize scores with average normalization factor
        for (Result factoid : extracted) {
            float norm = (float) (factoid.getScore() * topNormFactor);
            factoid.setNormScore(norm);
        }
    }
    return results;
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Result(info.ephyra.search.Result)

Example 24 with Hashtable

use of java.util.Hashtable in project hackpad by dropbox.

the class Parser method function.

private Node function(int functionType) throws IOException, ParserException {
    int syntheticType = functionType;
    // line number where source starts
    int baseLineno = ts.getLineno();
    int functionSourceStart = decompiler.markFunctionStart(functionType);
    String name;
    Node memberExprNode = null;
    if (matchToken(Token.NAME)) {
        name = ts.getString();
        decompiler.addName(name);
        if (!matchToken(Token.LP)) {
            if (compilerEnv.isAllowMemberExprAsFunctionName()) {
                // Extension to ECMA: if 'function <name>' does not follow
                // by '(', assume <name> starts memberExpr
                Node memberExprHead = nf.createName(name);
                name = "";
                memberExprNode = memberExprTail(false, memberExprHead);
            }
            mustMatchToken(Token.LP, "msg.no.paren.parms");
        }
    } else if (matchToken(Token.LP)) {
        // Anonymous function
        name = "";
    } else {
        name = "";
        if (compilerEnv.isAllowMemberExprAsFunctionName()) {
            // Note that memberExpr can not start with '(' like
            // in function (1+2).toString(), because 'function (' already
            // processed as anonymous function
            memberExprNode = memberExpr(false);
        }
        mustMatchToken(Token.LP, "msg.no.paren.parms");
    }
    if (memberExprNode != null) {
        syntheticType = FunctionNode.FUNCTION_EXPRESSION;
    }
    boolean nested = insideFunction();
    FunctionNode fnNode = nf.createFunction(name);
    if (nested || nestingOfWith > 0) {
        // 1. Nested functions are not affected by the dynamic scope flag
        // as dynamic scope is already a parent of their scope.
        // 2. Functions defined under the with statement also immune to
        // this setup, in which case dynamic scope is ignored in favor
        // of with object.
        fnNode.itsIgnoreDynamicScope = true;
    }
    int functionIndex = currentScriptOrFn.addFunction(fnNode);
    int functionSourceEnd;
    ScriptOrFnNode savedScriptOrFn = currentScriptOrFn;
    currentScriptOrFn = fnNode;
    int savedNestingOfWith = nestingOfWith;
    nestingOfWith = 0;
    Hashtable savedLabelSet = labelSet;
    labelSet = null;
    ObjArray savedLoopSet = loopSet;
    loopSet = null;
    ObjArray savedLoopAndSwitchSet = loopAndSwitchSet;
    loopAndSwitchSet = null;
    boolean savedHasReturnValue = hasReturnValue;
    int savedFunctionEndFlags = functionEndFlags;
    Node body;
    try {
        decompiler.addToken(Token.LP);
        if (!matchToken(Token.RP)) {
            boolean first = true;
            do {
                if (!first)
                    decompiler.addToken(Token.COMMA);
                first = false;
                mustMatchToken(Token.NAME, "msg.no.parm");
                String s = ts.getString();
                if (fnNode.hasParamOrVar(s)) {
                    addWarning("msg.dup.parms", s);
                }
                fnNode.addParam(s);
                decompiler.addName(s);
            } while (matchToken(Token.COMMA));
            mustMatchToken(Token.RP, "msg.no.paren.after.parms");
        }
        decompiler.addToken(Token.RP);
        mustMatchToken(Token.LC, "msg.no.brace.body");
        decompiler.addEOL(Token.LC);
        body = parseFunctionBody();
        mustMatchToken(Token.RC, "msg.no.brace.after.body");
        if (compilerEnv.isStrictMode() && !body.hasConsistentReturnUsage()) {
            String msg = name.length() > 0 ? "msg.no.return.value" : "msg.anon.no.return.value";
            addStrictWarning(msg, name);
        }
        decompiler.addToken(Token.RC);
        functionSourceEnd = decompiler.markFunctionEnd(functionSourceStart);
        if (functionType != FunctionNode.FUNCTION_EXPRESSION) {
            // Add EOL only if function is not part of expression
            // since it gets SEMI + EOL from Statement in that case
            decompiler.addToken(Token.EOL);
        }
    } finally {
        hasReturnValue = savedHasReturnValue;
        functionEndFlags = savedFunctionEndFlags;
        loopAndSwitchSet = savedLoopAndSwitchSet;
        loopSet = savedLoopSet;
        labelSet = savedLabelSet;
        nestingOfWith = savedNestingOfWith;
        currentScriptOrFn = savedScriptOrFn;
    }
    fnNode.setEncodedSourceBounds(functionSourceStart, functionSourceEnd);
    fnNode.setSourceName(sourceURI);
    fnNode.setBaseLineno(baseLineno);
    fnNode.setEndLineno(ts.getLineno());
    if (name != null) {
        int index = currentScriptOrFn.getParamOrVarIndex(name);
        if (index >= 0 && index < currentScriptOrFn.getParamCount())
            addStrictWarning("msg.var.hides.arg", name);
    }
    Node pn = nf.initFunction(fnNode, functionIndex, body, syntheticType);
    if (memberExprNode != null) {
        pn = nf.createAssignment(Token.ASSIGN, memberExprNode, pn);
        if (functionType != FunctionNode.FUNCTION_EXPRESSION) {
            // XXX check JScript behavior: should it be createExprStatement?
            pn = nf.createExprStatementNoReturn(pn, baseLineno);
        }
    }
    return pn;
}
Also used : Hashtable(java.util.Hashtable)

Example 25 with Hashtable

use of java.util.Hashtable in project che by eclipse.

the class AssistQuickFixTest18 method setUp.

//	public static Test suite() {
//		return setUpTest(new TestSuite(THIS));
//	}
//
//	public static Test setUpTest(Test test) {
//		return new Java18ProjectTestSetup(test);
//	}
@Before
public void setUp() throws Exception {
    super.setUp();
    Hashtable options = TestOptions.getDefaultOptions();
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
    JavaCore.setOptions(options);
    IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();
    store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);
    StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "//TODO\n${body_statement}", null);
    fJProject1 = Java18ProjectTestSetup.getProject();
    fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
}
Also used : Hashtable(java.util.Hashtable) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Before(org.junit.Before)

Aggregations

Hashtable (java.util.Hashtable)1278 Test (org.junit.Test)367 ArrayList (java.util.ArrayList)267 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)142 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)137 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)136 HashMap (java.util.HashMap)89 Bundle (org.osgi.framework.Bundle)82 BundleContext (org.osgi.framework.BundleContext)75 Configuration (org.osgi.service.cm.Configuration)75 Map (java.util.Map)73 IOException (java.io.IOException)67 ServiceRegistration (org.osgi.framework.ServiceRegistration)64 Enumeration (java.util.Enumeration)63 Dictionary (java.util.Dictionary)61 InitialContext (javax.naming.InitialContext)54 Vector (java.util.Vector)53 URL (java.net.URL)49 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)47 File (java.io.File)45