Skip to content

Commit

Permalink
Allow arbitrary strings as entity type
Browse files Browse the repository at this point in the history
This change is based on the discussion in Berlin last week.
It should be possible to add new entity types in the future,
maybe even in some local configuration, and hence the types
need to be extendable. The strings used to identify the known
types are the IRIs of the corresponding classes in the RDF
export.
  • Loading branch information
mkroetzsch committed Feb 18, 2014
1 parent 465f6ec commit 609d5b7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import org.wikidata.wdtk.datamodel.interfaces.EntityId;
import org.wikidata.wdtk.datamodel.interfaces.ItemId;

/**
Expand All @@ -46,8 +47,8 @@ public class ItemIdImpl extends EntityIdImpl implements ItemId {
}

@Override
public EntityType getEntityType() {
return EntityType.ITEM;
public String getEntityType() {
return EntityId.ET_ITEM;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import org.wikidata.wdtk.datamodel.interfaces.EntityId;
import org.wikidata.wdtk.datamodel.interfaces.PropertyId;

/**
Expand All @@ -46,8 +47,8 @@ public class PropertyIdImpl extends EntityIdImpl implements PropertyId {
}

@Override
public EntityType getEntityType() {
return EntityType.PROPERTY;
public String getEntityType() {
return EntityId.ET_PROPERTY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,22 @@
public interface EntityId extends IriValue {

/**
* Enum for the possible entity types, currently Item and Property.
*
* @author Markus Kroetzsch
* IRI of the type of an entity that is an item.
*/
static final String ET_ITEM = "http://www.wikidata.org/ontology#Item";
/**
* IRI of the type of an entity that is a property.
*/
enum EntityType {
ITEM, PROPERTY
}
static final String ET_PROPERTY = "http://www.wikidata.org/ontology#Property";

/**
* Get the type of this entity.
* Get the type of this entity. This should be an IRI that identifies an
* entity type, such as {@link EntityId#ET_ITEM} or
* {@link EntityId#ET_PROPERTY}.
*
* @return EntityType
* @return String
*/
EntityType getEntityType();
String getEntityType();

/**
* Get the id of this entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
* limitations under the License.
* #L%
*/
import org.wikidata.wdtk.datamodel.implementation.ItemIdImpl;
import org.wikidata.wdtk.datamodel.interfaces.EntityId;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
import org.wikidata.wdtk.datamodel.interfaces.EntityId;

public class ItemIdImplTest {

Expand All @@ -46,7 +46,7 @@ public void setUp() {

@Test
public void entityTypeIsItem() {
assertEquals(item1.getEntityType(), EntityId.EntityType.ITEM);
assertEquals(item1.getEntityType(), EntityId.ET_ITEM);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
* #L%
*/

import org.wikidata.wdtk.datamodel.interfaces.EntityId;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
import org.wikidata.wdtk.datamodel.interfaces.EntityId;

public class PropertyIdImplTest {

Expand All @@ -46,7 +47,7 @@ public void setUp() {

@Test
public void entityTypeIsProperty() {
assertEquals(prop1.getEntityType(), EntityId.EntityType.PROPERTY);
assertEquals(prop1.getEntityType(), EntityId.ET_PROPERTY);
}

@Test
Expand Down

0 comments on commit 609d5b7

Please sign in to comment.