Skip to content

Commit

Permalink
Added clone methods to all implementations of the Marking interface. …
Browse files Browse the repository at this point in the history
…Implementd a common behaviour regarding Set<String> attributes - the Set is always created during the construction and setUris or setTypes methods clear the existing internal Set and add all given Strings. Fixed two small issues inside a single JUnit test.
  • Loading branch information
MichaelRoeder committed Dec 10, 2015
1 parent a728b57 commit 1b11a41
Show file tree
Hide file tree
Showing 16 changed files with 1,120 additions and 988 deletions.
Binary file modified diagrams/importantTypes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
503 changes: 248 additions & 255 deletions diagrams/importantTypes.ucls

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.aksw</groupId>
<artifactId>gerbil.nif.transfer</artifactId>
<version>1.2.0</version>
<version>1.2.1-SNAPSHOT</version>
<name>NIF transfer library for the General Entity Annotator Benchmark</name>
<description>This project contains classes for transferring documents using NIF.</description>

Expand Down
62 changes: 32 additions & 30 deletions src/main/java/org/aksw/gerbil/transfer/nif/Marking.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
/**
* This file is part of NIF transfer library for the General Entity Annotator Benchmark.
*
* NIF transfer library for the General Entity Annotator Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NIF transfer library for the General Entity Annotator Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NIF transfer library for the General Entity Annotator Benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aksw.gerbil.transfer.nif;

/**
* A Marking belongs to a text and could mark a meaning inside the text or a
* topic covered by the whole text.
*
* @author Michael R&ouml;der ([email protected])
*
*/
public interface Marking {

@Override
public String toString();
}
/**
* This file is part of NIF transfer library for the General Entity Annotator Benchmark.
*
* NIF transfer library for the General Entity Annotator Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NIF transfer library for the General Entity Annotator Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NIF transfer library for the General Entity Annotator Benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aksw.gerbil.transfer.nif;

/**
* A Marking belongs to a text and could mark a meaning inside the text or a
* topic covered by the whole text.
*
* @author Michael R&ouml;der ([email protected])
*
*/
public interface Marking extends Cloneable {

@Override
public String toString();

public Object clone() throws CloneNotSupportedException;
}
16 changes: 16 additions & 0 deletions src/main/java/org/aksw/gerbil/transfer/nif/ScoredSpan.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* This file is part of NIF transfer library for the General Entity Annotator Benchmark.
*
* NIF transfer library for the General Entity Annotator Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NIF transfer library for the General Entity Annotator Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NIF transfer library for the General Entity Annotator Benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aksw.gerbil.transfer.nif;

public interface ScoredSpan extends Span, ScoredMarking {
Expand Down
246 changes: 127 additions & 119 deletions src/main/java/org/aksw/gerbil/transfer/nif/data/Annotation.java
Original file line number Diff line number Diff line change
@@ -1,119 +1,127 @@
/**
* This file is part of NIF transfer library for the General Entity Annotator Benchmark.
*
* NIF transfer library for the General Entity Annotator Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NIF transfer library for the General Entity Annotator Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NIF transfer library for the General Entity Annotator Benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aksw.gerbil.transfer.nif.data;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.aksw.gerbil.transfer.nif.Meaning;
import org.aksw.gerbil.transfer.nif.MeaningEqualityChecker;

/**
* An Annotation is a meaning which is added to a document.
*
* @author Michael Röder
*
*/
public class Annotation implements Meaning {

@Deprecated
protected String uri;
protected Set<String> uris = new HashSet<String>();

public Annotation(String uri) {
this.uri = uri;
this.uris.add(uri);
}

public Annotation(Set<String> uris) {
setUris(uris);
}

@Deprecated
@Override
public String getUri() {
return uri;
}

@Deprecated
@Override
public void setUri(String uri) {
this.uri = uri;
this.uris.clear();
this.uris.add(uri);
}

@Override
public Set<String> getUris() {
return uris;
}

@Override
public void setUris(Set<String> uris) {
this.uris = uris;
if (uris.size() > 0) {
this.uri = uris.iterator().next();
} else {
this.uri = null;
}
}

@Override
public void addUri(String uri) {
this.uris.add(uri);
if (this.uri == null) {
this.uri = uri;
}
}

@Override
public boolean containsUri(String uri) {
return uris.contains(uri);
}

@Override
public String toString() {
return "Annotation [uri=" + Arrays.toString(uris.toArray()) + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uris == null) ? 0 : uris.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Annotation other = (Annotation) obj;
if (uris == null) {
if (other.uris != null)
return false;
} else if (!MeaningEqualityChecker.overlaps(this, other))
return false;
return true;
}

}
/**
* This file is part of NIF transfer library for the General Entity Annotator Benchmark.
*
* NIF transfer library for the General Entity Annotator Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NIF transfer library for the General Entity Annotator Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NIF transfer library for the General Entity Annotator Benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
package org.aksw.gerbil.transfer.nif.data;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.aksw.gerbil.transfer.nif.Meaning;
import org.aksw.gerbil.transfer.nif.MeaningEqualityChecker;

/**
* An Annotation is a meaning which is added to a document.
*
* @author Michael Röder
*
*/
public class Annotation implements Meaning {

@Deprecated
protected String uri;
protected Set<String> uris = new HashSet<String>();

public Annotation(String uri) {
this.uri = uri;
this.uris.add(uri);
}

public Annotation(Set<String> uris) {
setUris(uris);
}

public Annotation(Annotation annotation) {
setUris(annotation.getUris());
}

@Deprecated
@Override
public String getUri() {
return uri;
}

@Deprecated
@Override
public void setUri(String uri) {
this.uri = uri;
this.uris.clear();
this.uris.add(uri);
}

@Override
public Set<String> getUris() {
return uris;
}

@Override
public void setUris(Set<String> uris) {
this.uris = uris;
if (uris.size() > 0) {
this.uri = uris.iterator().next();
} else {
this.uri = null;
}
}

@Override
public void addUri(String uri) {
this.uris.add(uri);
if (this.uri == null) {
this.uri = uri;
}
}

@Override
public boolean containsUri(String uri) {
return uris.contains(uri);
}

@Override
public String toString() {
return "Annotation [uri=" + Arrays.toString(uris.toArray()) + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((uris == null) ? 0 : uris.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Annotation other = (Annotation) obj;
if (uris == null) {
if (other.uris != null)
return false;
} else if (!MeaningEqualityChecker.overlaps(this, other))
return false;
return true;
}

@Override
public Object clone() throws CloneNotSupportedException {
return new Annotation(this);
}
}
Loading

0 comments on commit 1b11a41

Please sign in to comment.