Download the PHP package the-don-himself/twitter-graph without Composer
On this page you can find all versions of the php package the-don-himself/twitter-graph. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download the-don-himself/twitter-graph
More information about the-don-himself/twitter-graph
Files in the-don-himself/twitter-graph
Package twitter-graph
Short Description An example graph database implementation of Twitter using the Gremlin OGM library.
License MIT
Informations about the package twitter-graph
twitter-graph
Sample code of an example graph database implementation of Twitter using the The-Don-Himself/gremlin-ogm library.
Create A Schema
Note: Not all gremlin compatible databases support schemas, in the event you are using one just skip this part.
First we deal with vertexes (a few places I called them vertices, similar to indices and indexes)
Vertexes
`
Edges
And an edge
`
The beauty of this library is that it only helps you write gremlin commands but does not stop you from interfacing with Gremlin directly, for example as in the case of the Follows Edge above, the library will produce gremlin commands to create an edge between two vertexes if you can pass to it a unique identifier such as user_id, house_id, taxi_id, etc. If you want to added an edge by other ways you can simply write a gremlin command and submit it directly through $graph_connection->send(' my awesome gremlin command ;');
The follows edges class is really simple, in that it simply creates an edge linking two vertexes by user_id, in real life examples you'd probably create the edge but have added properties like followed_on, via_app, introduced_by and so on. Just add those properties to the class and let the library serialize them for you.
Create Schema
When creating vertex and edge classes, look at the code from \TheDonHimself\TwitterGraph\Commands, They include;
SchemaCheckCommand; SchemaCreateCommand; PopulateCommand; VertexesCountCommand; VertexesDropCommand; EdgesCountCommand; EdgesDropCommand; GremlinTraversalCommand;
SchemaCheckCommand runs some checks to ensure that you did not duplicate names of properties and labels or indexes while SchemaCreateCommand actually iterates through you graph classes and send gremlin commands to create them. PopulateCommand populates the graph with data either from an API as with the case of the sample TwitterGraph or from a databases if you use Doctrine ORM (RDBMS) and/or Doctrine ODM (MongoDB). GremlinTraversalCommand let you send a gremlin command through the CLI e.g php bin/graph twittergraph:gremlin:traversal --traversal="g.V().count()".
Traverse The Graph
The library is almost a seamless transition from the Gremlin API. The most important thing here is the TraversalBuilder from \TheDonHimself\Traversal\TraversalBuilder which returns ready to execute gremlin commands, for example to get back a users vertex from Twitter you can build a Traversal as follows
`
Take special note of the single and double quotes
Echoing this command will show you this `
If you want to use bindings in the case of script parameterization (highly recommended) you can do this.
`
Again please take special note of the single and double quotes
Echoing this command will show you this `
Re: check possible traversal steps in at the code from \TheDonHimself\Traversal\Step,
Let' get a little bit more complex now, fetching a user's feed
`
Echoing this command will show you this `
That's it for now, there is so much more that this simple library can do, please look in the sample TwitterGraph folder to quickly get started with a sample graph of your Twitter friends, followers, likes, tweets and retweets by running this command. The library comes with a preconfigured readonly Twitter App for this.
Tests
Currently, I've not written any test suites but you can test the library by using a sample Twitter Graph that comes preconfigured with this library. Only the following Graph Databases have been tested to work though will test more when I get the time/resources
- [x] Azure Cosmos DB
- [x] JanusGraph on Compose
- [x] JanusGraph Self-Hosted
Simple configure any of them in their respective yaml files in the root folder then execute the following
`
then
`
Azure Cosmos DB
Please Note: Schema create command not applicable for CosmosDB
example:
`
JanusGraph on Compose
example:
`
JanusGraph Self-Hosted
example:
`
GraphQL
You might also be interested in graphql2gremlin, an attempt to create a standard around transforming GraphQL queries to Gremlin Traversals.
All versions of twitter-graph with dependencies
abraham/twitteroauth Version ^1.0
symfony/console Version ^5.0 || ^4.0 || ^3.0
symfony/yaml Version ^5.0 || ^4.0 || ^3.0
the-don-himself/gremlin-ogm Version ^0.5