org.grobid.core.layout.BoundingBox Java Examples

The following examples show how to use org.grobid.core.layout.BoundingBox. 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: NLPLeaderboardTable.java    From science-result-extractor with Apache License 2.0 5 votes vote down vote up
private double calculateDistanceOfTwoBox(BoundingBox box1, BoundingBox to) {
    if (box1.getPage() != to.getPage()) {
        return 1000 * Math.abs(box1.getPage() - to.getPage());
    }

    //the current box is completely "lefter"
    boolean left = box1.getX2() < to.getX();
    boolean right = to.getX2() < box1.getX();
    boolean bottom = to.getY2() < box1.getY();
    boolean top = box1.getY2() < to.getY();
    if (top && left) {
        return dist(box1.getX2(), box1.getY2(), to.getX(), to.getY());
    } else if (left && bottom) {
        return dist(box1.getX2(), box1.getY(), to.getX(), to.getY2());
    } else if (bottom && right) {
        return dist(box1.getX(), box1.getY(), to.getX2(), to.getY2());
    } else if (right && top) {
        return dist(box1.getX(), box1.getY2(), to.getX2(), to.getY());
    } else if (left) {
        return to.getX() - box1.getX2();
    } else if (right) {
        return box1.getX() - to.getX2();
    } else if (bottom) {
        return box1.getY() - to.getY2();
    } else if (top) {
        return to.getY() - box1.getY2();
    } else {
        return 0;
    }

}
 
Example #2
Source File: TaggingTokenClusteror.java    From science-result-extractor with Apache License 2.0 4 votes vote down vote up
public List<TaggingTokenCluster> cluster() {
        
        List<TaggingTokenCluster> result = new ArrayList<>();

        PeekingIterator<LabeledTokensContainer> it = Iterators.peekingIterator(taggingTokenSynchronizer);
        if (!it.hasNext() || (it.peek() == null)) {
            return Collections.emptyList();
        }

        // a boolean is introduced to indicate the start of the sequence in the case the label
        // has no beginning indicator (e.g. I-)
        boolean begin = true;
        TaggingTokenCluster curCluster = new TaggingTokenCluster(it.peek().getTaggingLabel());
        BoundingBox curBox=null;
 
        
        
        while (it.hasNext()) {
            LabeledTokensContainer cont = it.next();
            BoundingBox b = BoundingBox.fromLayoutToken(cont.getLayoutTokens().get(0));
            if(!curCluster.concatTokens().isEmpty()){
                curBox = BoundingBox.fromLayoutToken(curCluster.concatTokens().get(0));
                if(b.distanceTo(curBox)>600){
                    curCluster = new TaggingTokenCluster(cont.getTaggingLabel());
                    result.add(curCluster);
                }
            }
            
            if (begin || cont.isBeginning() || cont.getTaggingLabel() != curCluster.getTaggingLabel()) {
                curCluster = new TaggingTokenCluster(cont.getTaggingLabel());
                result.add(curCluster);
            }
            
            //for table, seperate caption and content
            if(curCluster!=null){
                String tableStr = LayoutTokensUtil.normalizeText(curCluster.concatTokens());
                if(tableStr.matches(".*?(Table|TABLE) \\d+(:|\\.| [A-Z]).*?")){
//                if(tableStr.matches(".*?(Table|TABLE|Figure|FIGURE) \\d+(:|\\.).*?")){
                    if(toText(curCluster.getLastContainer().getLayoutTokens()).equalsIgnoreCase(". \n\n")){ 
                        curCluster = new TaggingTokenCluster(cont.getTaggingLabel());
                        result.add(curCluster);
                    }
                }
            }
                    
                    
            curCluster.addLabeledTokensContainer(cont);
            if (begin)
                begin = false;
        }

        return result;
    }
 
Example #3
Source File: NerdEntity.java    From entity-fishing with Apache License 2.0 4 votes vote down vote up
public void setBoundingBoxes(List<BoundingBox> boundingBoxes) {
	this.boundingBoxes = boundingBoxes;
}
 
Example #4
Source File: NerdEntity.java    From entity-fishing with Apache License 2.0 4 votes vote down vote up
public List<BoundingBox> getBoundingBoxes() {
	return boundingBoxes;
}
 
Example #5
Source File: NerdEntity.java    From entity-fishing with Apache License 2.0 4 votes vote down vote up
public void addBoundingBoxes(BoundingBox boundingBox) {
	if (this.boundingBoxes == null)
		this.boundingBoxes = new ArrayList<BoundingBox>();
	this.boundingBoxes.add(boundingBox);
}
 
Example #6
Source File: Mention.java    From entity-fishing with Apache License 2.0 4 votes vote down vote up
public void setBoundingBoxes(List<BoundingBox> boundingBoxes) {
    this.boundingBoxes = boundingBoxes;
}
 
Example #7
Source File: Mention.java    From entity-fishing with Apache License 2.0 4 votes vote down vote up
public List<BoundingBox> getBoundingBoxes() {
    return boundingBoxes;
}
 
Example #8
Source File: Mention.java    From entity-fishing with Apache License 2.0 4 votes vote down vote up
public void addBoundingBoxes(BoundingBox boundingBox) {
    if (this.boundingBoxes == null)
        this.boundingBoxes = new ArrayList<BoundingBox>();
    this.boundingBoxes.add(boundingBox);
}
 
Example #9
Source File: Entity.java    From grobid-ner with Apache License 2.0 4 votes vote down vote up
public void setBoundingBoxes(List<BoundingBox> boundingBoxes) {
	this.boundingBoxes = boundingBoxes;
}
 
Example #10
Source File: Entity.java    From grobid-ner with Apache License 2.0 4 votes vote down vote up
public List<BoundingBox> getBoundingBoxes() {
	return boundingBoxes;
}
 
Example #11
Source File: Entity.java    From grobid-ner with Apache License 2.0 4 votes vote down vote up
public void addBoundingBoxes(BoundingBox boundingBox) {
	if (this.boundingBoxes == null)
		this.boundingBoxes = new ArrayList<BoundingBox>();
	this.boundingBoxes.add(boundingBox);
}