Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectArrayList#size()

The following examples show how to use it.unimi.dsi.fastutil.objects.ObjectArrayList#size() . 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: FixSumsAndSubtractions.java    From WarpPI with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction,
		final ObjectArrayList<Function> functionsList) throws Error {
	if (currentFunction instanceof Sum || currentFunction instanceof Subtraction || currentFunction instanceof SumSubtraction) {
		if (currentFunction.getParameter(0) == null && currentFunction.getParameter(1) == null) {
			if (curIndex.i - 1 >= 0 && curIndex.i + 1 < functionsList.size()) {
				final Function next = functionsList.get(curIndex.i + 1);
				final Function prev = functionsList.get(curIndex.i - 1);
				functionsList.set(curIndex.i, currentFunction.setParameter(0, prev).setParameter(1, next));
				functionsList.remove(curIndex.i + 1);
				functionsList.remove(curIndex.i - 1);
				curIndex.i--;
				return true;
			} else if (currentFunction.getParameter(0) == null || currentFunction.getParameter(1) == null) {
				throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
			}
		}
	}
	return false;
}
 
Example 2
Source File: FastUtil.java    From minie with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Given a list of lists, return all the combinations between the lists (i.e. their indices). For example, suppose we
 * have the list of lists: [[1, 2, 3], [4, 5], [6, 7, 8]]. Then, this function will return:
 * [[0, 1], [1, 0], [0, 2], [2, 0], [1, 2], [2, 1], 
 *  [0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1]]
 * @param lists: list of lists
 * @return
 */
public static <T> ObjectArrayList<IntArrayList> getListsCombinationIndices(ObjectArrayList<ObjectArrayList<T>> lists){
    ObjectArrayList<IntArrayList> combinationsInd = new ObjectArrayList<>();
    ObjectArrayList<IntArrayList> result = new ObjectArrayList<>();
    int[][] combinations;
    
    for (int k = 2; k <= lists.size(); k++){
        result.clear();
        combinations = null;
        
        combinations = getCombinations(k, lists.size());
        
        for (int i = 0; i < combinations.length; i++) {
            IntArrayList indices = new IntArrayList();
            for (int j = 0; j < combinations[i].length; j++) {
                indices.add(combinations[i][j]);
            }
            permute(indices, 0, result);
        }
        combinationsInd.addAll(result);
    }
    return combinationsInd;
}
 
Example 3
Source File: FastUtil.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a list of lists, get the combinations of the elements between the lists.
 * For example, if we have lists = [[1, 2, 3], [4, 5]], then 
 * getElementsCombinations(lists) = [1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5] 
 * @param lists: list of lists
 * @return combination of elements between the lists
 */
public static <T> Set<ObjectArrayList<T>> getElementsCombinations(ObjectArrayList<ObjectArrayList<T>> lists) {
    Set<ObjectArrayList<T>> combinations = new HashSet<ObjectArrayList<T>>();
    Set<ObjectArrayList<T>> newCombinations = new HashSet<ObjectArrayList<T>>();
    ObjectArrayList<T> newList = new ObjectArrayList<T>();
    
    int index = 0;

    // Extract each of the integers in the first list and add each to ints as a new list
    for(T i: lists.get(0)) {
        newList.clear();
        newList.add(i);
        combinations.add(newList.clone());
    }
    index++;
    List<T> nextList;
    while(index < lists.size()) {
        nextList = lists.get(index).clone();
        newCombinations.clear();
        for(List<T> first: combinations) {
            for(T second: nextList) {
                newList.clear();
                newList.addAll(first);
                newList.add(second);
                newCombinations.add(newList.clone());
            }
        }
        combinations = newCombinations;

        index++;
        nextList.clear();
    }

    return combinations;
}
 
Example 4
Source File: CoreNLPUtils.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a sequence of indexed words and a verb, get all the verbs 'chained' to the word from the right.
 * @param sequence: a list of words
 * @param wordInd: the word index from where the search starts 
 * @return a list of verbs which precede 'word'
 */
private static IntArrayList getChainedVerbsFromRight(ObjectArrayList<IndexedWord> sequence, 
        IntArrayList chainedVerbs, int wordInd){
    // If the word is the rightiest word or it's not a verb - return
    if (wordInd < sequence.size()-1 && isVerb(sequence.get(wordInd + 1).tag())){
        chainedVerbs.add(wordInd + 1);
        getChainedVerbsFromRight(sequence, chainedVerbs, wordInd + 1);
    }
    
    return chainedVerbs;
}
 
Example 5
Source File: CoreNLPUtils.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a list of indexed words and a semantic graph, return the root word of the word list. We assume that
 * all the words from the list can be found in the semantic graph sg, and the words in wordList are connected
 * within the semantic graph of the sentence - sg. If there are multiple words which have the shortest distance
 * to the sentence root, then choose the most-left verb. 
 * 
 * @param sg: sentence semantic graph
 * @param wordsList: list of words from which to choose "root" from
 * @return
 */
public static IndexedWord getVerbRootFromWordList(SemanticGraph sg, ObjectArrayList<IndexedWord> wordList){
    IndexedWord constituentRoot = null;
    IntArrayList shortestDirectedPathDistances = new IntArrayList();
    
    int minPathToRoot = Integer.MAX_VALUE;
    int pathToRoot = -1;
    
    for (int i = 0; i < wordList.size(); i++){
        // The words with index -2 are the ones that cannot be found in the semantic graph (synthetic words)
        // This happens in the relations (see in clausie.ClauseDetector.java), and those words are the head words
        if (wordList.get(i).index() == -2){
            return wordList.get(i);
        }
        pathToRoot = sg.getShortestDirectedPathNodes(sg.getFirstRoot(), wordList.get(i)).size();
        if (pathToRoot < minPathToRoot){
            minPathToRoot = pathToRoot;
        }
        shortestDirectedPathDistances.add(pathToRoot);
    }
    
    // If the shortest path is one element, return it, else, return the first verb containing that index
    if (FastUtil.countElement(minPathToRoot, shortestDirectedPathDistances) == 1)
        return wordList.get(shortestDirectedPathDistances.indexOf(minPathToRoot));
    else {
        for (int i = 0; i < shortestDirectedPathDistances.size(); i++){
            if (shortestDirectedPathDistances.getInt(i) == minPathToRoot){
                if (isVerb(wordList.get(i).tag())){
                    constituentRoot = wordList.get(i);
                    break;
                }
            }
        }
    }
    
    return constituentRoot;
}
 
Example 6
Source File: CoreNLPUtils.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a list of words, return the phrase of words' lemmas as a whole string, separated with empty space
 * @param words: list of words (e.g. [She, is, pretty])
 * @return string of the list of words separated by space (e.g. it returns "She be pretty")
 */
public static String listOfWordsToLemmaString(ObjectArrayList<IndexedWord> words){
    StringBuffer sbSentence = new StringBuffer();
    for (int i = 0; i < words.size(); i++){
        sbSentence.append(words.get(i).lemma());
        sbSentence.append(SEPARATOR.SPACE);
    }
    return sbSentence.toString().trim();
}
 
Example 7
Source File: MultiplicationMethod1.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
public static ObjectArrayList<Function> execute(final Function f) throws Error, InterruptedException {
	Function result;
	final MathContext root = f.getMathContext();
	final ObjectArrayList<Function> elements = MultiplicationMethod1.getMultiplicationElements(f);
	final int[] workingElementCouple = MultiplicationMethod1.getFirstWorkingMultiplicationCouple(elements);
	final Function elem1 = elements.get(workingElementCouple[0]);
	final Function elem2 = elements.get(workingElementCouple[1]);

	final int size = elements.size();
	Function prec = new Multiplication(root, elem1, elem2);
	for (int i = size - 1; i >= 0; i--) {
		if (Thread.interrupted()) {
			throw new InterruptedException();
		}
		if (i != workingElementCouple[0] & i != workingElementCouple[1]) {
			final Function a = prec;
			final Function b = elements.get(i);
			prec = new Multiplication(root, a, b);
		}
	}

	result = prec;

	final ObjectArrayList<Function> results = new ObjectArrayList<>();
	results.add(result);
	return results;
}
 
Example 8
Source File: CoreNLPUtils.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a list of indexed words, return a list of strings, which contain the words
 * @param words: list of indexed words
 * @return list of strings (the words from 'words')
 */
public static ObjectArrayList<String> listOfWordsToWordsStringList(ObjectArrayList<IndexedWord> words){
    ObjectArrayList<String> stWords = new ObjectArrayList<String>();
    for (int i = 0; i < words.size(); i++){
        stWords.add(words.get(i).word());
    }
    return stWords;
}
 
Example 9
Source File: Utils.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
public static Function[][] joinFunctionsResults(final ObjectArrayList<ObjectArrayList<Function>> ln) {
	final int[] sizes = new int[ln.size()];
	for (int i = 0; i < ln.size(); i++) {
		sizes[i] = ln.get(i).size();
	}
	final int[] curs = new int[sizes.length];
	int total = 0;
	for (int i = 0; i < ln.size(); i++) {
		if (i == 0) {
			total = sizes[i];
		} else {
			total *= sizes[i];
		}
	}
	final Function[][] results = new Function[total][sizes.length];
	for (int i = 0; i < total; i++) {
		results[i] = new Function[sizes.length];
		for (int j = 0; j < sizes.length; j++) {
			results[i][j] = ln.get(j).get(curs[j]);
		}
		for (int k = 0; k < sizes.length; k++) {
			if (i % sizes[k] == 0) {
				for (int l = 0; l < sizes.length; l++) {
					if (l != k) {
						curs[l] += 1;
					}
				}
			}
		}
		for (int k = 0; k < sizes.length; k++) {
			if (curs[k] >= sizes[k]) {
				curs[k] = 0;
			}
		}
	}
	return results;
}
 
Example 10
Source File: PLIBuilder.java    From winter with Apache License 2.0 5 votes vote down vote up
public static List<PositionListIndex> getPLIs(ObjectArrayList<List<String>> records, int numAttributes, boolean isNullEqualNull) throws InputIterationException {
	if (records.size() > Integer.MAX_VALUE)
		throw new RuntimeException("PLI encoding into integer based PLIs is not possible, because the number of records in the dataset exceeds Integer.MAX_VALUE. Use long based plis instead! (NumRecords = " + records.size() + " and Integer.MAX_VALUE = " + Integer.MAX_VALUE);
	
	List<HashMap<String, IntArrayList>> clusterMaps = calculateClusterMapsStatic(records, numAttributes);
	return fetchPositionListIndexesStatic(clusterMaps, isNullEqualNull);
}
 
Example 11
Source File: Minimization.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a list of matched core maps (a phrase) and a list of words which are candidates for dropping ('remWords'), 
 * check if some of them form sub-constituents of 'matchCoreMaps' which are found in the dictionary.
 * If there are, remove them from 'remWords'. The words left in 'remWords' are the ones that couldn't be matched
 * with a sub-constituent found in the dictionary, i.e. those are the ones that we drop.
 * @param matchCoreMaps: list of words as a list of CoreMap object (a phrase)
 * @param remWords: list of candidates to be dropped (each word in 'remWord' can also be found in 'matchCoreMaps')
 */
public void dropWordsNotFoundInDict(List<CoreMap> matchCoreMaps, List<CoreMap> remWords){
    // Get all the sub-constituents
    ObjectArrayList<IndexedWord> words = CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(matchCoreMaps);
    SubConstituent sc = new SubConstituent(this.sg, CoreNLPUtils.getRootFromWordList(this.sg, words), words);
    sc.generateSubConstituentsFromLeft();
    ObjectOpenHashSet<String> subconstituents = sc.getStringSubConstituents();
    
    // Sub-constituents' strings found in the dictionary
    ObjectArrayList<String> scStringsInDict = new ObjectArrayList<>();
    for (String s: subconstituents){
        if (this.mwe.contains(s)){
            scStringsInDict.add(s);
        }
    }
    
    // If sub-constituents's strings are found in the dictionary, detect the words associated with them
    // and remove them.
    if (scStringsInDict.size() > 0){
        Iterator<CoreMap> iter = remWords.iterator();
        for (String stInDict: scStringsInDict){
            while (iter.hasNext()){   
                CoreMap cm = iter.next();
                CoreLabel cl = new CoreLabel(cm);
                if (stInDict.contains(cl.lemma().toLowerCase())){
                    iter.remove();
                }
            }
        }
    }
    
    // Drop the words not found in frequent/collocation sub-constituents
    this.dropWords(remWords, matchCoreMaps);
}
 
Example 12
Source File: ComposedCallbackBuilder.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private ComposedCallback( final ObjectArrayList<Callback> callbacks ) {
	super();
	this.callbacks = callbacks;
	this.size = callbacks.size();
	this.cont = new boolean[ size ];
	this.callback = new Callback[ size ];
	this.callbacks.toArray( callback );
}
 
Example 13
Source File: ImmutableBinaryTrieTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void testImmutableBinaryTrie( List<String> strings ) {
		ObjectArrayList<BitVector> vectors = new ObjectArrayList<BitVector>();
		for( int i = 0; i < strings.size(); i++ ) {
			BitVector v = LongArrayBitVector.ofLength( strings.get( i ).length() );
			for( int j = 0; j < strings.get( i ).length(); j++ ) if ( strings.get( i ).charAt( j ) == '1' ) v.set( j );
			vectors.add( v );
		}

		ImmutableBinaryTrie<BitVector> t = new ImmutableBinaryTrie<BitVector>( vectors, TransformationStrategies.identity() );
		
		assertEquals( vectors.size(), t.size() );
		for( int i = 0; i < vectors.size(); i++ ) assertEquals( vectors.get( i ).toString(), i, t.getLong( vectors.get( i ) ) );
}
 
Example 14
Source File: HyFD.java    From winter with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
private void executeFDEP() throws AlgorithmExecutionException {
	// Initialize
	Logger.getInstance().writeln("Initializing ...");
	RelationalInput relationalInput = this.getInput();
	this.initialize(relationalInput);
	
	// Load data
	Logger.getInstance().writeln("Loading data ...");
	ObjectArrayList<List<String>> records = this.loadData(relationalInput);
	this.closeInput(relationalInput);
	
	// Create default output if input is empty
	if (records.isEmpty()) {
		ObjectArrayList<ColumnIdentifier> columnIdentifiers = this.buildColumnIdentifiers();
		for (int attr = 0; attr < this.numAttributes; attr++)
			this.resultReceiver.receiveResult(new FunctionalDependency(new ColumnCombination(), columnIdentifiers.get(attr)));
		return;
	}
	
	int numRecords = records.size();
	
	// Calculate plis
	Logger.getInstance().writeln("Calculating plis ...");
	List<PositionListIndex> plis = PLIBuilder.getPLIs(records, this.numAttributes, this.valueComparator.isNullEqualNull());
	records = null; // we proceed with the values in the plis
	
	// Calculate inverted plis
	Logger.getInstance().writeln("Inverting plis ...");
	int[][] invertedPlis = this.invertPlis(plis, numRecords);

	// Extract the integer representations of all records from the inverted plis
	Logger.getInstance().writeln("Extracting integer representations for the records ...");
	int[][] compressedRecords = new int[numRecords][];
	for (int recordId = 0; recordId < numRecords; recordId++)
		compressedRecords[recordId] = this.fetchRecordFrom(recordId, invertedPlis);
	
	// Execute fdep
	Logger.getInstance().writeln("Executing fdep ...");
	FDEP fdep = new FDEP(this.numAttributes, this.valueComparator);
	FDTree fds = fdep.execute(compressedRecords);
	
	// Output all valid FDs
	Logger.getInstance().writeln("Translating fd-tree into result format ...");
	List<FunctionalDependency> result = fds.getFunctionalDependencies(this.buildColumnIdentifiers(), plis);
	plis = null;
	int numFDs = 0;
	for (FunctionalDependency fd : result) {
		//Logger.getInstance().writeln(fd);
		this.resultReceiver.receiveResult(fd);
		numFDs++;
	}
	Logger.getInstance().writeln("... done! (" + numFDs + " FDs)");
}
 
Example 15
Source File: MinIE.java    From minie with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Process possessives in the object.
 * If we have ("SUBJ", "REL", "NP_1 POS NP_2"), then: ("SUBJ", "REL + NP_1 + of", "NP_2")
 * @param prop: proposition (list of annotated phrases)
 */
public void processPoss(ObjectArrayList<AnnotatedPhrase> prop){
    // If there's no object (clause type SV), return
    if (prop.size() < 3)
        return;
    
    AnnotatedPhrase object = prop.get(2);
    AnnotatedPhrase rel = prop.get(1);
    TokenSequencePattern tPattern = TokenSequencePattern.compile(REGEX.T_NP_POS_NP);
    TokenSequenceMatcher tMatcher = tPattern.getMatcher(object.getWordCoreLabelList());
    
    int posIndex = -1;
    
    while (tMatcher.find()){         
        List<CoreMap> match = tMatcher.groupNodes();
        
        // Check if the first/last word of the match is the first/last word of the object
        CoreLabel firstWord = new CoreLabel(match.get(0));
        CoreLabel lastWord = new CoreLabel(match.get(match.size() - 1));
        boolean check = false;
        if (firstWord.index() == object.getWordList().get(0).index()){
            if (lastWord.index() == object.getWordList().get(object.getWordList().size() - 1).index()){
                check = true;
            }
        }
        if (!check) break;
        
        for (CoreMap cm: match){
            CoreLabel cl = new CoreLabel(cm);
            if (cl.tag().equals(POS_TAG.POS) && (cl.ner().equals(NE_TYPE.NO_NER))){
                posIndex = object.getWordCoreLabelList().indexOf(cl);
                break;
            }
        }
    }
    
    if (posIndex > -1){
        IndexedWord of = new IndexedWord();
        of.setOriginalText("of");
        of.setLemma("of");
        of.setWord("of");
        of.setTag("IN");
        of.setNER("O");
        of.setIndex(-1);
        
        ObjectArrayList<IndexedWord> pushedWords = new ObjectArrayList<>();
        object.removeWordFromList(posIndex);
        for (int i = posIndex; i < object.getWordList().size(); i++){
            pushedWords.add(object.getWordList().get(i));
        }
        rel.addWordsToList(pushedWords);
        rel.addWordToList(of);
        object.removeWordsFromList(pushedWords);
    }
}
 
Example 16
Source File: HyFD.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
private void executeFDEP() throws AlgorithmExecutionException {
	// Initialize
	Logger.getInstance().writeln("Initializing ...");
	RelationalInput relationalInput = this.getInput();
	this.initialize(relationalInput);
	
	// Load data
	Logger.getInstance().writeln("Loading data ...");
	ObjectArrayList<List<String>> records = this.loadData(relationalInput);
	this.closeInput(relationalInput);
	
	// Create default output if input is empty
	if (records.isEmpty()) {
		ObjectArrayList<ColumnIdentifier> columnIdentifiers = this.buildColumnIdentifiers();
		for (int attr = 0; attr < this.numAttributes; attr++)
			this.resultReceiver.receiveResult(new FunctionalDependency(new ColumnCombination(), columnIdentifiers.get(attr)));
		return;
	}
	
	int numRecords = records.size();
	
	// Calculate plis
	Logger.getInstance().writeln("Calculating plis ...");
	List<PositionListIndex> plis = PLIBuilder.getPLIs(records, this.numAttributes, this.valueComparator.isNullEqualNull());
	records = null; // we proceed with the values in the plis
	
	// Calculate inverted plis
	Logger.getInstance().writeln("Inverting plis ...");
	int[][] invertedPlis = this.invertPlis(plis, numRecords);

	// Extract the integer representations of all records from the inverted plis
	Logger.getInstance().writeln("Extracting integer representations for the records ...");
	int[][] compressedRecords = new int[numRecords][];
	for (int recordId = 0; recordId < numRecords; recordId++)
		compressedRecords[recordId] = this.fetchRecordFrom(recordId, invertedPlis);
	
	// Execute fdep
	Logger.getInstance().writeln("Executing fdep ...");
	FDEP fdep = new FDEP(this.numAttributes, this.valueComparator);
	FDTree fds = fdep.execute(compressedRecords);
	
	// Output all valid FDs
	Logger.getInstance().writeln("Translating fd-tree into result format ...");
	List<FunctionalDependency> result = fds.getFunctionalDependencies(this.buildColumnIdentifiers(), plis);
	plis = null;
	int numFDs = 0;
	for (FunctionalDependency fd : result) {
		//Logger.getInstance().writeln(fd);
		this.resultReceiver.receiveResult(fd);
		numFDs++;
	}
	Logger.getInstance().writeln("... done! (" + numFDs + " FDs)");
}
 
Example 17
Source File: Utils.java    From minie with GNU General Public License v3.0 4 votes vote down vote up
/**
 * formats an annotated proposition in Ollie style
 * @param proposition: annotated proposition to format
 * @return formatted proposition
 */
public static String formatProposition(AnnotatedProposition proposition) {
    // First the triple
    StringJoiner tripleJoiner = new StringJoiner(";", "(", ")");
    String subject = proposition.getSubject().toString();
    if (!subject.isEmpty()) tripleJoiner.add(subject);
    String relation = proposition.getRelation().toString();
    if (!relation.isEmpty()) tripleJoiner.add(relation);
    String object = proposition.getObject().toString();
    if (!object.isEmpty()) tripleJoiner.add(object);
    
    // Factuality
    String factualityString = "";
    String factuality = formatFactuality(proposition.getPolarity().getType().toString(), proposition.getModality().getModalityType().toString());
    if (!factuality.isEmpty()) factualityString = String.format("[factuality=%s]", factuality);
    
    /*String clausalModifier = proposition.getClauseModifier().toString();
    if (!clausalModifier.isEmpty()) annotations.add("clausalModifier=" + clausalModifier);*/

    // Attribution
    Attribution attribution = proposition.getAttribution();
    String attributionString = "";
    
    // Only process the attribution if there is a attribution phrase TODO is this suitable?
    if (attribution != null && attribution.getAttributionPhrase() != null) {
        StringJoiner attributionAttributesJoiner = new StringJoiner(";");
        String attributionPhrase = attribution.getAttributionPhrase().toString();
        if (!attributionPhrase.isEmpty()) attributionAttributesJoiner.add("phrase:" + attributionPhrase);
        String attributionPredicate = attribution.getPredicateVerb().toString();
        if (!attributionPredicate.isEmpty()) attributionAttributesJoiner.add("predicate:" + attributionPredicate);
        String attributionFactuality = formatFactuality(attribution.getPolarityType().toString(), attribution.getModalityType().toString());
        if (!attributionFactuality.isEmpty()) attributionAttributesJoiner.add("factuality:" + attributionFactuality);
        attributionString = String.format("[attribution=%s]", attributionAttributesJoiner.toString());
    }

    // Quantities
    StringJoiner quantityJoiner = new StringJoiner(";");
    String quantitiesString = "";
    ObjectArrayList<Quantity> quantities = new ObjectArrayList<Quantity>();

    // Add all quantities
    quantities.addAll(proposition.getSubject().getQuantities());
    quantities.addAll(proposition.getRelation().getQuantities());
    quantities.addAll(proposition.getObject().getQuantities());
    if (quantities.size() > 0) {
        for (Quantity q : quantities) {
            StringJoiner quantityPhrase = new StringJoiner(" ");
            for (IndexedWord w : q.getQuantityWords()) {
                quantityPhrase.add(w.originalText());
            }
            quantityJoiner.add(String.format("QUANT_%s:%s", q.getId(),quantityPhrase.toString()));
        }
        quantitiesString = String.format("[quantities=%s]", quantityJoiner.toString());
    }
    String output = tripleJoiner.toString() + factualityString + attributionString + quantitiesString;
    return output;
}
 
Example 18
Source File: MinIE.java    From minie with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Given a proposition, check if it should be pruned or not.
 * @param proposition
 * @return true, if the proposition should be pruned, false otherwise
 */
private boolean pruneAnnotatedProposition(ObjectArrayList<AnnotatedPhrase> proposition){
    AnnotatedPhrase subj = proposition.get(0);
    AnnotatedPhrase rel = proposition.get(1);

    // If there is no verb in the relation, prune
    // TODO: check why this is happening! In some of these cases, the verb gets deleted for some reason.
    // This happens when CCs are being processed. Empty relations too
    if (!CoreNLPUtils.hasVerb(rel.getWordList()))
        return true;

    // Empty subject
    if (subj.getWordList().isEmpty())
        return true;

    if (proposition.size() == 3){
        AnnotatedPhrase obj = proposition.get(2);
        // Check if the object is empty (shouldn't happen, but just in case)
        if (obj.getWordList().isEmpty())
            return true;

        // The last word of the object
        IndexedWord w = obj.getWordList().get(obj.getWordList().size()-1);

        // If the last word is preposition
        if (w.tag().equals(POS_TAG.IN) && w.ner().equals(NE_TYPE.NO_NER))
            return true;

        // When the object is consisted of one preposition
        if (obj.getWordList().size() == 1){
            // If the object is just one preposition - prune
            if (w.tag().equals(POS_TAG.IN) || w.tag().equals(POS_TAG.TO)){
                return true;
            }
        }
        // When the object ends with one of the POS tags: WDT, WP$, WP or WRB
        if (w.tag().equals(POS_TAG.WDT) || w.tag().equals(POS_TAG.WP) ||
                w.tag().equals(POS_TAG.WP_P) || w.tag().equals(POS_TAG.WRB)){
            return true;
        }

        // Prune if clause modifier detected
        if (this.detectClauseModifier(proposition)){
            return true;
        }

        // Prune if there are NERs on both sides of "be" relation
        // TODO: do this for implicit extractions only?
        if ((rel.getWordList().size() == 1)) {
            if (rel.getWordList().get(0).lemma().equals("be")) {
                if (subj.isOneNER() && obj.isOneNER()) {
                    if (!obj.getWordList().get(0).ner().equals(NE_TYPE.MISC)) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
Example 19
Source File: ParallelFilteredProcessorRunner.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
private static ObjectArrayList<Step<?>> copySteps(ObjectArrayList<Step<?>> steps) {
	final ObjectArrayList<Step<?>> copy = new ObjectArrayList<>(steps.size());
	for(final Step<?> step: steps) copy.add(step.copy());
	return copy;
}
 
Example 20
Source File: CallGraphGenerator.java    From fasten with Apache License 2.0 4 votes vote down vote up
private static String graph2String(final CallGraphGenerator callGraphGenerator, final int i, final RandomGenerator randomGenerator) {
	final ArrayListMutableGraph g = callGraphGenerator.rcgs[i];
	final StringBuilder sb = new StringBuilder();
	sb.append("{\n");
	sb.append("\t\"product\": \"graph-" + i + "\",\n");
	sb.append("\t\"forge\": \"f\",\n");
	sb.append("\t\"generator\": \"OPAL\",\n");
	sb.append("\t\"version\": \"1.0\",\n");
	sb.append("\t\"timestamp\": \"0\",\n");
	sb.append("\t\"depset\": [\n\t\t");
	// All generated DNFs are singletons
	for(final IntIterator d = callGraphGenerator.deps[i].iterator(); d.hasNext(); ) {
		sb.append( "[{ \"forge\": \"f\", \"product\": \"graph-" + d.nextInt() + "\", \"constraints\": [\"[1.0]\"] }]");
		if (d.hasNext()) sb.append(", ");
	}
	sb.append("\n\t],\n");
	sb.append("\t\"cha\": {\n");
	for (int jj = 0; jj < g.numNodes() / 3; jj++) {			
		sb.append("\t\t\"/p" + i + "/A" + jj + "\": {\n");
		sb.append("\t\t\t\"methods\": {\n");
		for (int j = 3 * jj; j < 3 * jj + 3 && j < g.numNodes(); j++) {
			sb.append("\t\t\t\t\"" + j + "\": \"/p" + i + "/A" + jj + ".f" + j + "()v\"");
			if (j < 3 * jj + 2 && j < g.numNodes() + 1) sb.append(",");
			sb.append("\n");
		}
		sb.append("\t\t\t},\n");
		sb.append("\t\t\t\"superInterfaces\": [],\n");
		sb.append("\t\t\t\"sourceFile\": \"A" + jj + ".java\",\n");
		sb.append("\t\t\t\"superClasses\": [\"/java.lang/Object\"]\n");
		sb.append("\t\t}");
		if (jj < g.numNodes() / 3 - 1) sb.append(",");
		sb.append("\n");
	}
	sb.append("\t},\n");
	sb.append("\t\"graph\": {\n");
	
	// Internal calls
	sb.append("\t\t\"internalCalls\": [\n");
	final ObjectArrayList<String> lines = new ObjectArrayList<>(); // Graph lines
	for(int j = 0; j < g.numNodes(); j++) {
		for(final IntIterator s = g.successors(j); s.hasNext();)
			lines.add("\t\t\t[\n\t\t\t\t" + callGraphGenerator.nodePermutation[i][j] + ",\n\t\t\t\t" + callGraphGenerator.nodePermutation[i][s.nextInt()] + "\n\t\t\t]");
	}
	Collections.shuffle(lines, new Random(randomGenerator.nextLong())); // Permute graph lines
	for (int j = 0; j < lines.size(); j++) {
		sb.append(lines.get(j));
		if (j < lines.size() - 1) sb.append(",");
		sb.append("\n");
	}
	sb.append("\t\t],\n");
	
	// External calls
	sb.append("\t\t\"externalCalls\": [\n");
	lines.clear();
	for(final int[] t: callGraphGenerator.source2Targets[i]) {
		lines.add("\t\t\t[\n\t\t\t\t\"" + callGraphGenerator.nodePermutation[i][t[0]] + "\",\n\t\t\t\t\"/p" + t[1] + "/A"+ callGraphGenerator.nodePermutation[t[1]][t[2]] / 3 + ".f" + callGraphGenerator.nodePermutation[t[1]][t[2]] +"()v\",\n"
				+ "\t\t\t\t{\"invokevirtual\": \"1\"}\n"
				+ "\t\t\t]");
	}
	Collections.shuffle(lines, new Random(randomGenerator.nextLong())); // Permute graph lines
	for (int j = 0; j < lines.size(); j++) {
		sb.append(lines.get(j));
		if (j < lines.size() - 1) sb.append(",");
		sb.append("\n");
	}
	sb.append("\t\t]\n");
	sb.append("\t}\n");
	sb.append("}");
	
	return sb.toString();
}