Java源码示例:org.grobid.core.layout.BoundingBox
示例1
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;
}
}
示例2
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;
}
示例3
public void setBoundingBoxes(List<BoundingBox> boundingBoxes) {
this.boundingBoxes = boundingBoxes;
}
示例4
public List<BoundingBox> getBoundingBoxes() {
return boundingBoxes;
}
示例5
public void addBoundingBoxes(BoundingBox boundingBox) {
if (this.boundingBoxes == null)
this.boundingBoxes = new ArrayList<BoundingBox>();
this.boundingBoxes.add(boundingBox);
}
示例6
public void setBoundingBoxes(List<BoundingBox> boundingBoxes) {
this.boundingBoxes = boundingBoxes;
}
示例7
public List<BoundingBox> getBoundingBoxes() {
return boundingBoxes;
}
示例8
public void addBoundingBoxes(BoundingBox boundingBox) {
if (this.boundingBoxes == null)
this.boundingBoxes = new ArrayList<BoundingBox>();
this.boundingBoxes.add(boundingBox);
}
示例9
public void setBoundingBoxes(List<BoundingBox> boundingBoxes) {
this.boundingBoxes = boundingBoxes;
}
示例10
public List<BoundingBox> getBoundingBoxes() {
return boundingBoxes;
}
示例11
public void addBoundingBoxes(BoundingBox boundingBox) {
if (this.boundingBoxes == null)
this.boundingBoxes = new ArrayList<BoundingBox>();
this.boundingBoxes.add(boundingBox);
}