-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proof of concept for Freebase db link-up #42
- Loading branch information
Showing
8 changed files
with
303 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Application\Migrations; | ||
|
||
use Doctrine\DBAL\Migrations\AbstractMigration, | ||
Doctrine\DBAL\Schema\Schema; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your need! | ||
*/ | ||
class Version20130328022931 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema) | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); | ||
|
||
$this->addSql("ALTER TABLE acts_shows ADD freebase_id VARCHAR(255)"); | ||
} | ||
|
||
public function down(Schema $schema) | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); | ||
|
||
$this->addSql("ALTER TABLE acts_shows DROP freebase_id"); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/Acts/CamdramBackendBundle/Command/ShowsFreebaseCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
namespace Acts\CamdramBackendBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use Acts\CamdramBundle\Entity\Show; | ||
use Doctrine\ORM\EntityRepository; | ||
|
||
class ShowsFreebaseCommand extends ContainerAwareCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('camdram:shows:freebase') | ||
->setDescription('Map shows to freebase plays') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
|
||
$em = $this->getContainer()->get('doctrine.orm.entity_manager'); | ||
/** @var $repo EntityRepository */ | ||
$repo = $em->getRepository('ActsCamdramBundle:Show'); | ||
|
||
$shows = $repo->findBy(array('freebase_id' => null)); | ||
$social = $this->getContainer()->get('acts.social_api.provider'); | ||
$api = $social->get('google_simple'); | ||
|
||
$i = 0; | ||
|
||
foreach ($shows as $show) { | ||
$results = $api->doFreebaseSearch($show->getName(), '(any type:/theater/play type:/theater/opera)', 2); | ||
if (count($results) > 1 && ($results[0]['score'] > 150 || $results[0]['name'] == $show->getName())) { | ||
$show->setFreebaseId($results[0]['mid']); | ||
$output->writeln('Mapped show "'.$show->getName().'" to Freebase play "' | ||
.$results[0]['name'].'" ('.$results[0]['mid'].')'); | ||
|
||
} | ||
if ($i % 30 == 0) { | ||
$em->flush(); | ||
} | ||
$i++; | ||
} | ||
$em->flush(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Acts\CamdramBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Acts\CamdramBundle\Entity\Play; | ||
|
||
class PlayController extends Controller | ||
{ | ||
|
||
public function displayAction($mid) | ||
{ | ||
$social = $this->get('acts.social_api.provider'); | ||
$api = $social->get('google_simple'); | ||
|
||
$topic = $api->doFreebaseTopic($mid); | ||
$play = new Play($topic); | ||
|
||
$shows = $this->getDoctrine()->getRepository('ActsCamdramBundle:Show')->findBy(array('freebase_id' => $topic['id'])); | ||
|
||
return $this->render('ActsCamdramBundle:Play:display.html.twig', array('play' => $play, 'shows' => $shows)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Acts\CamdramBundle\Entity; | ||
|
||
/** | ||
* Play (or other theatrical work) | ||
* | ||
*/ | ||
class Play | ||
{ | ||
private $data; | ||
|
||
public function __construct($data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
public function getMid() | ||
{ | ||
return $this->data['id']; | ||
} | ||
|
||
protected function getValue($key, $array = false) | ||
{ | ||
if ($array) { | ||
return $this->data['property'][$key]['values']; | ||
} | ||
else { | ||
return $this->data['property'][$key]['values'][0]; | ||
} | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->getValue('/type/object/name'); | ||
} | ||
|
||
public function getDescription() | ||
{ | ||
return $this->getValue('/common/topic/description'); | ||
} | ||
|
||
public function getAuthor() | ||
{ | ||
return $this->getValue('/book/written_work/author', true); | ||
} | ||
|
||
public function getPlaywright() | ||
{ | ||
return $this->getValue('/theater/play/playwright', true); | ||
} | ||
|
||
public function getComposer() | ||
{ | ||
return $this->getValue('/theater/play/composer', true); | ||
} | ||
|
||
public function getLyricist() | ||
{ | ||
return $this->getValue('/theater/play/lyricist', true); | ||
} | ||
|
||
public function getOrchestrator() | ||
{ | ||
return $this->getValue('/theater/play/orchestrator', true); | ||
} | ||
|
||
public function getCharacters() | ||
{ | ||
return $this->getValue('/theater/play/characters', true); | ||
} | ||
|
||
public function getSoundtracks() | ||
{ | ||
return $this->getValue('/theater/play/soundtracks', true); | ||
} | ||
|
||
public function getProductions() | ||
{ | ||
return $this->getValue('/theater/play/productions', true); | ||
} | ||
|
||
public function getUrl() | ||
{ | ||
return 'https://www.freebase.com/'.$this->getMid(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/Acts/CamdramBundle/Resources/views/Play/display.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{% extends 'ActsCamdramBundle::layout.html.twig' %} | ||
|
||
{% block title %}Play: {{ play.name.text }}{% endblock %} | ||
|
||
{% block body %} | ||
|
||
<div class="row"> | ||
<div class="twelve columns"> | ||
|
||
<h2>{{ play.name.text }}</h2> | ||
|
||
{% if play.playwright | length > 0 %} | ||
<h5>Author</h5> | ||
<p>{% for playwright in play.playwright %}{{ playwright.text }}<br/>{% endfor %}</p> | ||
{% endif %} | ||
{% if play.composer | length > 0 %} | ||
<h5>Composer</h5> | ||
<p>{% for composer in play.composer %}{{ composer.text }}<br/>{% endfor %}</p> | ||
{% endif %} | ||
{% if play.lyricist | length > 0 %} | ||
<h5>Lyricist</h5> | ||
<p>{% for lyricist in play.lyricist %}{{ lyricist.text }}<br/>{% endfor %}</p> | ||
{% endif %} | ||
{% if play.orchestrator | length > 0 %} | ||
<h5>Orchestrator</h5> | ||
<p>{% for orchestrator in play.orchestrator %}{{ orchestrator.text }}<br/>{% endfor %}</p> | ||
{% endif %} | ||
|
||
<p>{{ play.description.value }}</p> | ||
|
||
<h3>Characters</h3> | ||
<ul> | ||
{% for character in play.characters %} | ||
<li>{{ character.text }}</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
{% if play.soundtracks | length > 0 %} | ||
<h3>Cast Recordings</h3> | ||
<ul> | ||
{% for soundtrack in play.soundtracks %} | ||
<li><a href="https://www.freebase.com{{ soundtrack.id }}">{{ soundtrack.text }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if shows | length > 0 %} | ||
<h3>Performances</h3> | ||
<ul class="block-grid two-up mobile"> | ||
{% for show in shows %} | ||
<li> | ||
{% if show.society %}<a href="{{ path('get_society', {identifier: show.society}) }}">{{ show.society.name }}</a>{% endif %} | ||
<h5><a href="{{ path('get_show', {identifier: show.slug}) }}">{{ show.name }}</a></h5> | ||
<p><em>{% include 'ActsCamdramBundle:Performance:show.html.twig' with {'performances': show.performances } %}</em></p> | ||
{{ show.description | truncate(200) | camdram_markdown }} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters