/** * Completes all the named entities' data accumulated before (plus some * additional data, such as some context string) to the database. */ protected function save() { $this->entities->rewind(); while ($this->entities->valid()) { $entity = $this->entities->current(); $containerindex = $this->entities->getInfo(); // Get the text context. list($entity->contextstart, $entity->notation, $entity->contextend) = $this->extractText($entity->xmlid, $containerindex); foreach (explode(' ', $entity->identifier) as $identifier) { // Each entry in array $tag['key'] points to a different target. If // there are multiple entries, we have to add multiple records to // support links with multiple targets. Note: save() below will // always insert a new record, therefore it doesn't matter that // we pass the same object several times. $entity->identifier = $identifier; $this->entityGateway->save($entity); } $this->entities->detach($entity); unset($entity); } }
/** * @test */ public function findEntitiesBySearchCriteria() { $ent = new NamedEntity(); $ent->xmlid = 'e1'; $ent->page = 22; $ent->chunk = 33; $ent->domain = 'person'; $ent->identifier = 44; $ent->notation = 'Entity 1'; $this->obj->save($ent); $ent = new NamedEntity(); $ent->xmlid = 'e2'; $ent->page = 55; $ent->chunk = 66; $ent->domain = 'place'; $ent->identifier = 44; $ent->notation = 'Entity 2'; $this->obj->save($ent); $objs = $this->obj->find(); $this->assertInternalType('array', $objs); $this->assertTrue(2 == count($objs)); $objs = $this->obj->find('domain = person'); $this->assertInternalType('array', $objs); $this->assertTrue(1 == count($objs)); $objs = $this->obj->find('domain == artwork'); $this->assertInternalType('array', $objs); $this->assertTrue(0 == count($objs)); $objs = $this->obj->find('identifier != 19'); $this->assertInternalType('array', $objs); $this->assertTrue(2 == count($objs)); $objs = $this->obj->find('identifier != 19'); $this->assertInternalType('array', $objs); $this->assertTrue(2 == count($objs)); $objs = $this->obj->find('page >= 22', ' chunk<>66'); $this->assertInternalType('array', $objs); $this->assertTrue(1 == count($objs)); $this->assertSame('Entity 1', $objs[0]->notation); }