├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── README.md ├── pom.xml ├── twitlogic-core ├── .gitignore ├── LICENSE.txt ├── example.properties ├── firehose.sh ├── places-demo.sh ├── pom.xml ├── src │ ├── main │ │ ├── antlr3 │ │ │ └── net │ │ │ │ └── fortytwo │ │ │ │ └── twitlogic │ │ │ │ └── syntax │ │ │ │ ├── afterthought │ │ │ │ └── Afterthought.g │ │ │ │ └── twiple │ │ │ │ └── Twiple.g │ │ ├── java │ │ │ ├── edu │ │ │ │ └── rpi │ │ │ │ │ ├── cs │ │ │ │ │ └── datascience │ │ │ │ │ │ └── EarthquakeTweets.java │ │ │ │ │ └── tw │ │ │ │ │ └── twctwit │ │ │ │ │ ├── LoadSWCData.java │ │ │ │ │ ├── TWCTwitDemo.java │ │ │ │ │ ├── pubsub │ │ │ │ │ ├── PairSet.java │ │ │ │ │ └── SubscriptionManager.java │ │ │ │ │ └── query │ │ │ │ │ ├── ConferenceInferencer.java │ │ │ │ │ ├── QueryPlay.java │ │ │ │ │ ├── RelatedHashtagsInferencer.java │ │ │ │ │ ├── RelatedHashtagsResource.java │ │ │ │ │ ├── RelatedTweetsResource.java │ │ │ │ │ └── SimpleInferencer.java │ │ │ ├── net │ │ │ │ └── fortytwo │ │ │ │ │ └── twitlogic │ │ │ │ │ ├── TweetContext.java │ │ │ │ │ ├── TweetFilterCriterion.java │ │ │ │ │ ├── TwitLogic.java │ │ │ │ │ ├── TwitLogicAgent.java │ │ │ │ │ ├── TwitLogicClientDemo.java │ │ │ │ │ ├── TwitLogicServerDemo.java │ │ │ │ │ ├── data │ │ │ │ │ ├── EdinburghAssociativeThesaurus.java │ │ │ │ │ ├── FreeAssociationGenerator.java │ │ │ │ │ └── USFFreeAssociationNorm.java │ │ │ │ │ ├── flow │ │ │ │ │ ├── ConcurrentBuffer.java │ │ │ │ │ ├── Filter.java │ │ │ │ │ ├── Handler.java │ │ │ │ │ ├── NullHandler.java │ │ │ │ │ └── Splitter.java │ │ │ │ │ ├── logging │ │ │ │ │ ├── TweetPersistedLogger.java │ │ │ │ │ ├── TweetReceivedLogger.java │ │ │ │ │ └── TweetStatistics.java │ │ │ │ │ ├── model │ │ │ │ │ ├── Dollartag.java │ │ │ │ │ ├── Entities.java │ │ │ │ │ ├── Hashtag.java │ │ │ │ │ ├── Person.java │ │ │ │ │ ├── Place.java │ │ │ │ │ ├── PlaceType.java │ │ │ │ │ ├── PlainLiteral.java │ │ │ │ │ ├── Resource.java │ │ │ │ │ ├── Triple.java │ │ │ │ │ ├── Tweet.java │ │ │ │ │ ├── TweetParseException.java │ │ │ │ │ ├── TypedLiteral.java │ │ │ │ │ ├── URIReference.java │ │ │ │ │ ├── User.java │ │ │ │ │ └── geo │ │ │ │ │ │ ├── Point.java │ │ │ │ │ │ └── Polygon.java │ │ │ │ │ ├── persistence │ │ │ │ │ ├── CoverageManager.java │ │ │ │ │ ├── DumpFileGeneratorTask.java │ │ │ │ │ ├── PersistenceContext.java │ │ │ │ │ ├── PersonResource.java │ │ │ │ │ ├── PlacePersistenceHelper.java │ │ │ │ │ ├── SailFactory.java │ │ │ │ │ ├── SesameTools.java │ │ │ │ │ ├── SimpleTweetContext.java │ │ │ │ │ ├── TweetDeleter.java │ │ │ │ │ ├── TweetPersister.java │ │ │ │ │ ├── TweetStore.java │ │ │ │ │ ├── TweetStoreClient.java │ │ │ │ │ ├── TweetStoreConnection.java │ │ │ │ │ ├── TweetStoreException.java │ │ │ │ │ ├── UserRegistry.java │ │ │ │ │ ├── beans │ │ │ │ │ │ ├── AdministrativeDivision.java │ │ │ │ │ │ ├── Agent.java │ │ │ │ │ │ ├── City.java │ │ │ │ │ │ ├── Country.java │ │ │ │ │ │ ├── Document.java │ │ │ │ │ │ ├── Feature.java │ │ │ │ │ │ ├── Graph.java │ │ │ │ │ │ ├── Image.java │ │ │ │ │ │ ├── MicroblogPost.java │ │ │ │ │ │ ├── Neighborhood.java │ │ │ │ │ │ ├── Point.java │ │ │ │ │ │ ├── PointOfInterest.java │ │ │ │ │ │ ├── SpatialThing.java │ │ │ │ │ │ └── UserAccount.java │ │ │ │ │ └── sail │ │ │ │ │ │ ├── AGRepositorySailFactory.java │ │ │ │ │ │ ├── MemoryStoreFactory.java │ │ │ │ │ │ ├── NativeStoreFactory.java │ │ │ │ │ │ └── Neo4jSailFactory.java │ │ │ │ │ ├── proof │ │ │ │ │ ├── AssumptionStep.java │ │ │ │ │ ├── InferenceStep.java │ │ │ │ │ ├── Information.java │ │ │ │ │ ├── NodeSet.java │ │ │ │ │ ├── NodeSetList.java │ │ │ │ │ ├── PMLConstruct.java │ │ │ │ │ └── Query.java │ │ │ │ │ ├── query │ │ │ │ │ ├── Extender.java │ │ │ │ │ ├── Memo.java │ │ │ │ │ ├── MemoizedRandomWalk.java │ │ │ │ │ ├── QueryResult.java │ │ │ │ │ └── QueryStuff.java │ │ │ │ │ ├── ranking │ │ │ │ │ ├── WeightedMatrix.java │ │ │ │ │ ├── WeightedValue.java │ │ │ │ │ └── WeightedVector.java │ │ │ │ │ ├── services │ │ │ │ │ ├── bitly │ │ │ │ │ │ ├── BitlyClient.java │ │ │ │ │ │ └── BitlyClientException.java │ │ │ │ │ ├── cliqset │ │ │ │ │ │ ├── CliqsetAPI.java │ │ │ │ │ │ └── CliqsetClient.java │ │ │ │ │ └── twitter │ │ │ │ │ │ ├── CommandListener.java │ │ │ │ │ │ ├── CustomTwitterClient.java │ │ │ │ │ │ ├── HandlerException.java │ │ │ │ │ │ ├── PlaceMappingQueue.java │ │ │ │ │ │ ├── RateLimiter.java │ │ │ │ │ │ ├── RestfulJSONClient.java │ │ │ │ │ │ ├── StatusStreamParser.java │ │ │ │ │ │ ├── TwitterAPI.java │ │ │ │ │ │ ├── TwitterAPIException.java │ │ │ │ │ │ ├── TwitterAPILimits.java │ │ │ │ │ │ ├── TwitterClient.java │ │ │ │ │ │ ├── TwitterClientException.java │ │ │ │ │ │ ├── TwitterConnectionRefusedException.java │ │ │ │ │ │ ├── TwitterConnectionResetException.java │ │ │ │ │ │ ├── TwitterCredentials.java │ │ │ │ │ │ ├── errors │ │ │ │ │ │ ├── BadGatewayException.java │ │ │ │ │ │ ├── BadRequestException.java │ │ │ │ │ │ ├── EnhanceYourCalmException.java │ │ │ │ │ │ ├── ForbiddenException.java │ │ │ │ │ │ ├── InternalServerErrorException.java │ │ │ │ │ │ ├── NotAcceptableException.java │ │ │ │ │ │ ├── NotFoundException.java │ │ │ │ │ │ ├── NotModifiedException.java │ │ │ │ │ │ ├── ServiceUnavailableException.java │ │ │ │ │ │ └── UnauthorizedException.java │ │ │ │ │ │ └── twitter4j │ │ │ │ │ │ ├── Twitter4jClient.java │ │ │ │ │ │ ├── Twitter4jLimits.java │ │ │ │ │ │ └── Twitter4jPlay.java │ │ │ │ │ ├── syntax │ │ │ │ │ ├── HashtagLexer.java │ │ │ │ │ ├── Lexicon.java │ │ │ │ │ ├── Matcher.java │ │ │ │ │ ├── MatcherException.java │ │ │ │ │ ├── MultiMatcher.java │ │ │ │ │ ├── TopicSniffer.java │ │ │ │ │ ├── TweetAnnotator.java │ │ │ │ │ ├── TweetSyntax.java │ │ │ │ │ ├── afterthought │ │ │ │ │ │ ├── AfterthoughtContext.java │ │ │ │ │ │ ├── AfterthoughtMatcher.java │ │ │ │ │ │ ├── AfterthoughtParserHelper.java │ │ │ │ │ │ ├── CompoundAfterthoughtMatcher.java │ │ │ │ │ │ ├── DatatypePropertyAfterthoughtMatcher.java │ │ │ │ │ │ ├── DemoAfterthoughtMatcher.java │ │ │ │ │ │ ├── ObjectPropertyAfterthoughtMatcher.java │ │ │ │ │ │ └── impl │ │ │ │ │ │ │ ├── OwlSameasMatcher.java │ │ │ │ │ │ │ ├── PmlIsPartOfMatcher.java │ │ │ │ │ │ │ ├── RdfsSeeAlsoMatcher.java │ │ │ │ │ │ │ ├── ReviewMatcher.java │ │ │ │ │ │ │ ├── TypeMatcher.java │ │ │ │ │ │ │ ├── contact │ │ │ │ │ │ │ ├── AddressMatcher.java │ │ │ │ │ │ │ ├── BirthdayMatcher.java │ │ │ │ │ │ │ ├── EmailAddressMatcher.java │ │ │ │ │ │ │ ├── FaxMatcher.java │ │ │ │ │ │ │ └── PhoneMatcher.java │ │ │ │ │ │ │ ├── foaf │ │ │ │ │ │ │ ├── FoafDepictionMatcher.java │ │ │ │ │ │ │ ├── FoafHomepageMatcher.java │ │ │ │ │ │ │ ├── FoafInterestMatcher.java │ │ │ │ │ │ │ ├── FoafKnowsMatcher.java │ │ │ │ │ │ │ ├── FoafMadeMatcher.java │ │ │ │ │ │ │ ├── FoafMakerMatcher.java │ │ │ │ │ │ │ ├── FoafPageMatcher.java │ │ │ │ │ │ │ └── SelfInterestMatcher.java │ │ │ │ │ │ │ ├── miscellaneous │ │ │ │ │ │ │ └── MentionedBy.java │ │ │ │ │ │ │ ├── openvocab │ │ │ │ │ │ │ ├── OVCategoryMatcher.java │ │ │ │ │ │ │ ├── OVDepictsMatcher.java │ │ │ │ │ │ │ ├── OVSimilarToMatcher.java │ │ │ │ │ │ │ ├── OVStudiesMatcher.java │ │ │ │ │ │ │ └── OVUsesMatcher.java │ │ │ │ │ │ │ └── skos │ │ │ │ │ │ │ ├── SkosBroaderMatcher.java │ │ │ │ │ │ │ ├── SkosNarrowerMatcher.java │ │ │ │ │ │ │ └── SkosRelatedMatcher.java │ │ │ │ │ ├── twannotations │ │ │ │ │ │ ├── TwannotationAttributeRdfizer.java │ │ │ │ │ │ ├── TwannotationRdfizer.java │ │ │ │ │ │ └── Twannotator.java │ │ │ │ │ └── twiple │ │ │ │ │ │ └── TwipleMatcher.java │ │ │ │ │ ├── util │ │ │ │ │ ├── CommonHttpClient.java │ │ │ │ │ ├── ExampleTweetHandler.java │ │ │ │ │ ├── Factory.java │ │ │ │ │ ├── PlaceMiner.java │ │ │ │ │ ├── ServerTestApp.java │ │ │ │ │ ├── SparqlUpdateTools.java │ │ │ │ │ ├── StoppableHandler.java │ │ │ │ │ ├── TweetMetrics.java │ │ │ │ │ ├── UdpTransactionSail.java │ │ │ │ │ ├── intervals │ │ │ │ │ │ ├── Interval.java │ │ │ │ │ │ └── IntervalSequence.java │ │ │ │ │ ├── misc │ │ │ │ │ │ ├── CSVExporter.java │ │ │ │ │ │ ├── Compression.java │ │ │ │ │ │ ├── FirehoseDemo.java │ │ │ │ │ │ ├── FriendFetcher.java │ │ │ │ │ │ ├── PlacesDemo.java │ │ │ │ │ │ └── ThroughputTesting.java │ │ │ │ │ └── properties │ │ │ │ │ │ ├── InvalidPropertyValueException.java │ │ │ │ │ │ ├── PropertyException.java │ │ │ │ │ │ ├── PropertyValueNotFoundException.java │ │ │ │ │ │ └── TypedProperties.java │ │ │ │ │ └── vocabs │ │ │ │ │ ├── Assumption.java │ │ │ │ │ ├── Contact.java │ │ │ │ │ ├── DBpediaResource.java │ │ │ │ │ ├── DCTerms.java │ │ │ │ │ ├── FOAF.java │ │ │ │ │ ├── Geo.java │ │ │ │ │ ├── GeoNames.java │ │ │ │ │ ├── MiscellaneousVocabs.java │ │ │ │ │ ├── OWL.java │ │ │ │ │ ├── OpenVocab.java │ │ │ │ │ ├── PML2Relation.java │ │ │ │ │ ├── PMLJustification.java │ │ │ │ │ ├── PMLProvenance.java │ │ │ │ │ ├── PMLTrust.java │ │ │ │ │ ├── RDF.java │ │ │ │ │ ├── RDFG.java │ │ │ │ │ ├── RDFS.java │ │ │ │ │ ├── Review.java │ │ │ │ │ ├── SIOC.java │ │ │ │ │ ├── SIOCT.java │ │ │ │ │ ├── SKOS.java │ │ │ │ │ ├── SWC.java │ │ │ │ │ └── TwitlogicVocabulary.java │ │ │ └── org │ │ │ │ └── jvcompress │ │ │ │ ├── lzo │ │ │ │ ├── LZOConstants.java │ │ │ │ ├── Min1Comp.java │ │ │ │ └── MiniLZO.java │ │ │ │ └── util │ │ │ │ └── MInt.java │ │ ├── python │ │ │ └── places │ │ │ │ ├── map_places.py │ │ │ │ ├── map_places.py~ │ │ │ │ └── more_places_mappings.numbers │ │ │ │ ├── Contents │ │ │ │ └── PkgInfo │ │ │ │ ├── QuickLook │ │ │ │ └── Thumbnail.jpg │ │ │ │ ├── document-thumbnail.tiff │ │ │ │ └── index.xml.gz │ │ └── resources │ │ │ ├── META-INF │ │ │ └── services │ │ │ │ ├── org.openrdf.query.parser.QueryParserFactory │ │ │ │ ├── org.openrdf.rio.RDFParserFactory │ │ │ │ └── org.openrdf.rio.RDFWriterFactory │ │ │ └── net │ │ │ └── fortytwo │ │ │ └── twitlogic │ │ │ ├── namespaces.ttl │ │ │ ├── twitlogic-void.ttl │ │ │ ├── twitlogic.example.properties │ │ │ ├── twitlogic.owl │ │ │ ├── twitterplaces.ttl │ │ │ └── util │ │ │ └── exampleTransaction.xml │ └── test │ │ └── java │ │ └── net │ │ └── fortytwo │ │ └── twitlogic │ │ ├── SparqlToolsTest.java │ │ ├── TwitLogicTest.java │ │ ├── data │ │ └── FreeAssociationGeneratorTest.java │ │ ├── persistence │ │ └── SesameToolsTest.java │ │ ├── services │ │ └── twitter │ │ │ └── TwitterAPITest.java │ │ ├── syntax │ │ ├── HashtagLexerTest.java │ │ ├── MatcherTestBase.java │ │ ├── TweetSyntaxTest.java │ │ ├── afterthought │ │ │ ├── AfterthoughtMatcherTest.java │ │ │ └── impl │ │ │ │ ├── RdfsSeeAlsoMatcherTest.java │ │ │ │ └── ReviewMatcherTest.java │ │ └── twiple │ │ │ └── TwipleMatcherTest.java │ │ └── util │ │ ├── PolygonTest.java │ │ └── intervals │ │ └── IntervalsTest.java ├── throughput-testing.sh ├── twitlogic-server.sh ├── twitlogic.sh └── website │ ├── demos │ ├── pfizer │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── lib │ │ │ ├── jquery │ │ │ │ └── 1.4.2 │ │ │ │ │ └── jquery.min.js │ │ │ └── timeago │ │ │ │ └── 0.8.2 │ │ │ │ └── jquery.timeago.js │ │ ├── pfizer.css │ │ └── pfizer.js │ ├── sparqlwidget │ │ ├── examples │ │ │ ├── all-tweets.sparql │ │ │ ├── iswc2010-subevents-tweets.sparql │ │ │ ├── iswc2010-tweets.sparql │ │ │ ├── paper-authors.sparql │ │ │ └── small_university_towns.sparql │ │ ├── images │ │ │ ├── busy-bouncing-white-14x14.gif │ │ │ ├── footer-sparkle-blue.png │ │ │ └── header-sparkle-blue.png │ │ ├── index.html │ │ ├── iswc2010.html │ │ ├── lib │ │ │ ├── flXHRproxy │ │ │ │ └── 1.2.2 │ │ │ │ │ └── jquery.flXHRproxy.js │ │ │ ├── jquery │ │ │ │ ├── 1.4.2 │ │ │ │ │ └── jquery.min.js │ │ │ │ └── 1.6.4 │ │ │ │ │ └── jquery.min.js │ │ │ ├── timeago │ │ │ │ └── 0.8.2 │ │ │ │ │ └── jquery.timeago.js │ │ │ └── xml2json │ │ │ │ └── 1.0 │ │ │ │ └── jquery.xml2json.js │ │ ├── swc.html │ │ └── v1 │ │ │ ├── sparql-widget.css │ │ │ └── sparql-widget.js │ └── twctwit │ │ ├── about.html │ │ ├── css │ │ └── style.css │ │ ├── data │ │ ├── sample.json │ │ └── tweets.json │ │ ├── img │ │ ├── aboutus-bg.gif │ │ ├── arrow-closed.gif │ │ ├── arrow-open.gif │ │ ├── close.png │ │ ├── content-bg.gif │ │ ├── logo.png │ │ ├── more.gif │ │ ├── ohyeah_button.png │ │ └── sidebar-bg.gif │ │ ├── index.html │ │ ├── js │ │ ├── facet.js │ │ ├── jquery.timeago.js │ │ ├── tags.js │ │ └── tweets.js │ │ └── test.html │ ├── divider.jpg │ ├── earthquaketweets │ └── archive │ │ └── twitlogic-full.rdf │ ├── favicon.ico │ ├── images │ ├── TwitLogic_logo_large.png │ ├── TwitLogic_logo_medium.png │ └── TwitLogic_logo_small.png │ ├── index.css │ ├── index.html │ ├── josh_email.png │ ├── mashup │ ├── inc │ │ ├── api-rdf.php │ │ ├── api-rdfstream.php │ │ ├── api-web.php │ │ └── constants.php │ └── twitter4rdf.php │ └── robots.txt ├── twitlogic-plugins ├── .gitignore ├── pom.xml └── twitlogic-larkc-plugin │ ├── .gitignore │ ├── LICENSE.txt │ ├── README.txt │ ├── TwitLogicPlugin.rdf │ ├── TwitLogicPlugin.wsdl │ ├── example.properties │ ├── pom.xml │ └── src │ ├── assembly │ └── full.xml │ └── main │ └── java │ └── net │ └── fortytwo │ └── twitlogic │ └── larkc │ ├── SimpleCallback.java │ ├── StatementQueuingListener.java │ ├── StreamingPlugin.java │ ├── StreamingQueueIterator.java │ ├── StreamingSetOfStatements.java │ ├── TwitLogicPlugin.java │ ├── TwitLogicPluginDemo.java │ ├── TwitterStream.java │ └── sail │ ├── QueueingSail.java │ └── QueueingSailConnection.java └── twitlogic-rdfagents ├── .gitignore ├── pom.xml └── src └── main ├── java └── net │ └── fortytwo │ └── twitlogic │ └── rdfagents │ ├── AgentDemo.java │ ├── RDFAgentsProviderDemo.java │ ├── TwitLogicAgent.java │ └── TwitLogicPubsubProvider.java └── resources └── META-INF └── services ├── org.openrdf.rio.RDFParserFactory └── org.openrdf.rio.RDFWriterFactory /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .classpath 3 | .project 4 | .settings 5 | .idea 6 | *.iml 7 | *~ 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | TwitLogic, Copyright (C) 2009-2014 Joshua Shinavier. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Welcome to the TwitLogic code base! 2 | 3 | ![TwitLogic logo|width=101px|height=132px](https://github.com/joshsh/twitlogic/wiki/graphics/TwitLogic_logo_small.png) 4 | 5 | Documentation: 6 | * [Syntax conventions](http://wiki.github.com/joshsh/twitlogic/syntax-conventions) for embedding structured content in Twitter messages 7 | * [Configuring and running TwitLogic](http://wiki.github.com/joshsh/twitlogic/configuring-and-running-twitlogic) 8 | * [TwitLogic Linked Data](http://wiki.github.com/joshsh/twitlogic/twitlogic-linked-data): crawling the knowledge base 9 | * [Semantic Twannotations](http://wiki.github.com/joshsh/twitlogic/semantic-twannotations): mapping Twitter Annotations into Semantic Web vocabularies 10 | 11 | See also TwitLogic's [home page](http://twitlogic.fortytwo.net). 12 | 13 | Please feel free to [ask questions](mailto:josh@fortytwo.net) or [raise issues](http://github.com/joshsh/twitlogic/issues). 14 | -------------------------------------------------------------------------------- /twitlogic-core/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .classpath 3 | .project 4 | .settings 5 | *.iml 6 | *~ 7 | -------------------------------------------------------------------------------- /twitlogic-core/LICENSE.txt: -------------------------------------------------------------------------------- 1 | TwitLogic, Copyright (C) 2009-2012 Joshua Shinavier. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /twitlogic-core/example.properties: -------------------------------------------------------------------------------- 1 | # This is an example TwitLogic configuration file. You will need to supply your 2 | # own Twitter user name and password in order to run the application. The other 3 | # values should be customized for your environment. See this page for details: 4 | # http://github.com/joshsh/twitlogic/wikis/configuring-and-running-twitlogic 5 | # Feel free to send questions to josh@fortytwo.net 6 | 7 | 8 | ######################################## 9 | # data sources 10 | 11 | net.fortytwo.twitlogic.followList0 = twit_logic/listenlist 12 | net.fortytwo.twitlogic.followUser0 = twit_logic 13 | 14 | net.fortytwo.twitlogic.trackTerms0 = #semanticweb, #linkeddata 15 | 16 | 17 | ######################################## 18 | # server 19 | 20 | net.fortytwo.twitlogic.server.baseURI = http://localhost:8182/ 21 | net.fortytwo.twitlogic.server.port = 8182 22 | net.fortytwo.twitlogic.server.staticContentDirectory = /tmp/twitlogic/website 23 | 24 | 25 | ######################################## 26 | # persistence 27 | 28 | net.fortytwo.twitlogic.persistence.sailClass = org.openrdf.sail.nativerdf.NativeStore 29 | net.fortytwo.twitlogic.persistence.nativeStoreDirectory = /tmp/twitlogic/data 30 | 31 | net.fortytwo.twitlogic.persistence.dump.file = /tmp/twitlogic/website/dump/twitlogic-full.trig.gz 32 | net.fortytwo.twitlogic.persistence.dump.interval = 300000 33 | 34 | 35 | ######################################## 36 | # Twitter authentication 37 | 38 | # Register a new Twitter application at https://dev.twitter.com/apps 39 | net.fortytwo.twitlogic.twitter.consumerKey = [application key] 40 | net.fortytwo.twitlogic.twitter.consumerSecret = [application secret] 41 | 42 | # For a user which has granted access to the application 43 | net.fortytwo.twitlogic.twitter.accessToken = [user token] 44 | net.fortytwo.twitlogic.twitter.accessTokenSecret = [user secret] 45 | 46 | 47 | ######################################## 48 | # bit.ly authentication 49 | 50 | # Note: you only need a bit.ly account if you're using the TwitLogic 51 | # query answering agent. 52 | net.fortytwo.twitlogic.services.bitly.login = [bit.ly user name] 53 | net.fortytwo.twitlogic.services.bitly.apiKey = [bit.ly API key] 54 | -------------------------------------------------------------------------------- /twitlogic-core/firehose.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Path to JAR 4 | JAR=`dirname $0`/target/twitlogic-*-full.jar 5 | 6 | # Find Java 7 | if [ "$JAVA_HOME" = "" ] ; then 8 | JAVA="java" 9 | else 10 | JAVA="$JAVA_HOME/bin/java" 11 | fi 12 | 13 | # Set Java options 14 | if [ "$JAVA_OPTIONS" = "" ] ; then 15 | JAVA_OPTIONS="-Xms32M -Xmx512M -XX:+HeapDumpOnOutOfMemoryError" 16 | fi 17 | 18 | # Launch the application 19 | $JAVA $JAVA_OPTIONS -cp target/classes:"target/dependency/*" net.fortytwo.twitlogic.util.misc.FirehoseDemo $* 20 | 21 | # Return the program's exit code 22 | exit $? 23 | -------------------------------------------------------------------------------- /twitlogic-core/places-demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Path to JAR 4 | JAR=`dirname $0`/target/twitlogic-*-full.jar 5 | 6 | # Find Java 7 | if [ "$JAVA_HOME" = "" ] ; then 8 | JAVA="java" 9 | else 10 | JAVA="$JAVA_HOME/bin/java" 11 | fi 12 | 13 | # Set Java options 14 | if [ "$JAVA_OPTIONS" = "" ] ; then 15 | JAVA_OPTIONS="-Xms32M -Xmx512M -XX:+HeapDumpOnOutOfMemoryError" 16 | fi 17 | 18 | # Launch the application 19 | $JAVA $JAVA_OPTIONS -cp target/classes:"target/dependency/*" net.fortytwo.twitlogic.util.misc.PlacesDemo $* 20 | 21 | # Return the program's exit code 22 | exit $? 23 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/edu/rpi/tw/twctwit/TWCTwitDemo.java: -------------------------------------------------------------------------------- 1 | package edu.rpi.tw.twctwit; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | import net.fortytwo.twitlogic.persistence.TweetStore; 5 | import net.fortytwo.twitlogic.services.twitter.TwitterClient; 6 | import net.fortytwo.twitlogic.services.twitter.twitter4j.Twitter4jClient; 7 | 8 | import java.io.FileInputStream; 9 | import java.io.File; 10 | import java.util.Properties; 11 | 12 | /** 13 | * @author Joshua Shinavier (http://fortytwo.net). 14 | */ 15 | public class TWCTwitDemo { 16 | 17 | public static void main(final String[] args) throws Exception { 18 | try { 19 | if (1 == args.length) { 20 | File configFile = new File(args[0]); 21 | Properties p = new Properties(); 22 | p.load(new FileInputStream(configFile)); 23 | TwitLogic.setConfiguration(p); 24 | 25 | runDemo(); 26 | } else { 27 | printUsage(); 28 | System.exit(1); 29 | } 30 | } catch (Throwable t) { 31 | t.printStackTrace(); 32 | System.exit(1); 33 | } 34 | } 35 | 36 | private static void printUsage() { 37 | System.out.println("Usage: twctwit [configuration file]"); 38 | System.out.println("For more information, please see:\n" 39 | + " ."); 40 | } 41 | 42 | private static void runDemo() throws Exception { 43 | // Create a persistent store. 44 | TweetStore store = new TweetStore(); 45 | store.initialize(); 46 | 47 | try { 48 | TwitterClient client = new Twitter4jClient(); 49 | 50 | //store.dump(System.out); 51 | //store.dumpToFile(new File("/tmp/twitlogic-tmp-dump.trig"), RDFFormat.TRIG); 52 | 53 | // Launch linked data server. 54 | store.startServer(client); 55 | 56 | Object mutex = ""; 57 | synchronized (mutex) { 58 | mutex.wait(); 59 | } 60 | } finally { 61 | store.shutDown(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/edu/rpi/tw/twctwit/pubsub/SubscriptionManager.java: -------------------------------------------------------------------------------- 1 | package edu.rpi.tw.twctwit.pubsub; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | 5 | import java.util.logging.Logger; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class SubscriptionManager { 11 | private static final Logger LOGGER = TwitLogic.getLogger(SubscriptionManager.class); 12 | 13 | private static final long MIN_ITERATION_TIME = 5000; 14 | 15 | private final Object mutex = ""; 16 | private boolean closed = false; 17 | private final PairSet subscriptions; 18 | 19 | public SubscriptionManager() { 20 | subscriptions = new PairSet(); 21 | 22 | new Thread(new Runnable() { 23 | public void run() { 24 | try { 25 | refreshUntilClosed(); 26 | } catch (InterruptedException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | }).start(); 31 | } 32 | 33 | public void close() { 34 | closed = true; 35 | } 36 | 37 | private void refreshAll() { 38 | 39 | } 40 | 41 | private void refreshUntilClosed() throws InterruptedException { 42 | long lastTime = System.currentTimeMillis(); 43 | 44 | while (!closed) { 45 | long currentTime = System.currentTimeMillis(); 46 | long d = currentTime - lastTime; 47 | if (d < MIN_ITERATION_TIME) { 48 | wait(MIN_ITERATION_TIME - d); 49 | currentTime += (MIN_ITERATION_TIME - d); 50 | LOGGER.info("query demand is is met at " 51 | + MIN_ITERATION_TIME + "ms cycle: " 52 | + subscriptionInfo()); 53 | } else { 54 | LOGGER.warning("query demand is over capacity at " 55 | + MIN_ITERATION_TIME + "ms cycle: " 56 | + subscriptionInfo() 57 | + " (" + (d - MIN_ITERATION_TIME) + "ms behind schedule)"); 58 | } 59 | 60 | lastTime = currentTime; 61 | refreshAll(); 62 | } 63 | } 64 | 65 | private String subscriptionInfo() { 66 | synchronized (mutex) { 67 | return "" + subscriptions.keySize() + " sources with " + subscriptions.valueSize() + " subscribers"; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/TweetContext.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic; 2 | 3 | import net.fortytwo.twitlogic.model.Person; 4 | import net.fortytwo.twitlogic.model.Resource; 5 | import net.fortytwo.twitlogic.model.Tweet; 6 | import net.fortytwo.twitlogic.model.User; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public interface TweetContext { 12 | User thisUser(); 13 | 14 | Person thisPerson(); 15 | 16 | User repliedToUser(); 17 | 18 | User retweetedUser(); 19 | 20 | Tweet thisTweet(); 21 | 22 | Tweet repliedToTweet(); 23 | 24 | Resource anonymousNode(); 25 | } 26 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/flow/ConcurrentBuffer.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.flow; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 4 | 5 | import java.util.Queue; 6 | import java.util.concurrent.ConcurrentLinkedQueue; 7 | 8 | /** 9 | * A buffered Handler which expects exactly one thread to write to it (via 10 | * handle) and one thread to read from it (via flush). 11 | * 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class ConcurrentBuffer implements Handler { 15 | private final Queue outQueue; 16 | private final Handler handler; 17 | 18 | public ConcurrentBuffer(final Handler handler) { 19 | this.handler = handler; 20 | outQueue = new ConcurrentLinkedQueue(); 21 | } 22 | 23 | public boolean isOpen() { 24 | return true; 25 | } 26 | 27 | public void handle(final T t) throws HandlerException { 28 | outQueue.add(t); 29 | } 30 | 31 | public boolean flush() throws HandlerException { 32 | int size = outQueue.size(); 33 | 34 | for (int i = 0; i < size; i++) { 35 | if (!handler.isOpen()) { 36 | break; 37 | } 38 | handler.handle(outQueue.remove()); 39 | } 40 | 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/flow/Filter.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.flow; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class Filter implements Handler { 9 | private final Handler baseHandler; 10 | private final Criterion criterion; 11 | 12 | public Filter(final Criterion criterion, 13 | final Handler baseHandler) { 14 | this.criterion = criterion; 15 | this.baseHandler = baseHandler; 16 | } 17 | 18 | public boolean isOpen() { 19 | return baseHandler.isOpen(); 20 | } 21 | 22 | public void handle(T t) throws HandlerException { 23 | if (criterion.allow(t)) { 24 | baseHandler.handle(t); 25 | } 26 | } 27 | 28 | public interface Criterion { 29 | boolean allow(S s); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/flow/Handler.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.flow; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 4 | 5 | /** 6 | * An object which consumes data of a certain type. 7 | * A Handler may close at any time: you should call isOpen before each call to handle 8 | * to make sure the handler can accept new input. 9 | * 10 | * @author Joshua Shinavier (http://fortytwo.net). 11 | */ 12 | public interface Handler { 13 | /** 14 | * @return whether this Handler is open for new input 15 | */ 16 | boolean isOpen(); 17 | 18 | /** 19 | * Consumes a piece of data and performs some operation on that data. 20 | * 21 | * @throws HandlerException if any error occurs while processing the data 22 | */ 23 | void handle(T t) throws HandlerException; 24 | } 25 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/flow/NullHandler.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.flow; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class NullHandler implements Handler { 9 | public boolean isOpen() { 10 | return true; 11 | } 12 | 13 | public void handle(T t) throws HandlerException { 14 | // Do nothing. 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/flow/Splitter.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.flow; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class Splitter implements Handler { 9 | private final Handler[] handlers; 10 | 11 | public Splitter(final Handler[] handlers) { 12 | this.handlers = handlers; 13 | } 14 | 15 | public boolean isOpen() { 16 | // TODO 17 | return true; 18 | } 19 | 20 | public void handle(final T t) throws HandlerException { 21 | for (Handler handler : handlers) { 22 | handler.handle(t); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/logging/TweetPersistedLogger.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.logging; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.model.Tweet; 5 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class TweetPersistedLogger implements Handler { 11 | private final TweetStatistics statistics; 12 | private final Handler baseHandler; 13 | 14 | public TweetPersistedLogger(final TweetStatistics statistics, 15 | final Handler baseHandler) { 16 | this.statistics = statistics; 17 | this.baseHandler = baseHandler; 18 | } 19 | 20 | public boolean isOpen() { 21 | return baseHandler.isOpen(); 22 | } 23 | 24 | public void handle(final Tweet tweet) throws HandlerException { 25 | baseHandler.handle(tweet); 26 | statistics.tweetPersisted(tweet); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/logging/TweetReceivedLogger.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.logging; 2 | 3 | import net.fortytwo.twitlogic.model.Tweet; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | import net.fortytwo.twitlogic.flow.Handler; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class TweetReceivedLogger implements Handler { 11 | private final TweetStatistics statistics; 12 | private final Handler baseHandler; 13 | 14 | public TweetReceivedLogger(final TweetStatistics statistics, 15 | final Handler baseHandler) { 16 | this.statistics = statistics; 17 | this.baseHandler = baseHandler; 18 | } 19 | 20 | public boolean isOpen() { 21 | return baseHandler.isOpen(); 22 | } 23 | 24 | public void handle(final Tweet tweet) throws HandlerException { 25 | baseHandler.handle(tweet); 26 | statistics.tweetReceived(tweet); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/Dollartag.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class Dollartag implements Resource { 7 | private final String name; 8 | 9 | public Dollartag(final String name) { 10 | this.name = name.trim().toUpperCase(); 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public String toString() { 18 | return "$" + name; 19 | } 20 | 21 | public Type getType() { 22 | return Type.DOLLARTAG; 23 | } 24 | 25 | public boolean equals(final Object other) { 26 | return other instanceof Dollartag 27 | && name.equals(((Dollartag) other).name); 28 | } 29 | 30 | public int hashCode() { 31 | return name.hashCode(); 32 | } 33 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/Entities.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPI; 4 | import org.json.JSONArray; 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | import twitter4j.HashtagEntity; 8 | import twitter4j.URLEntity; 9 | 10 | import java.util.Collection; 11 | import java.util.LinkedList; 12 | 13 | /** 14 | * @author Joshua Shinavier (http://fortytwo.net). 15 | */ 16 | public class Entities { 17 | private final Collection topics = new LinkedList(); 18 | private final Collection links = new LinkedList(); 19 | 20 | public Entities() { 21 | } 22 | 23 | public Entities(final HashtagEntity[] hashtagEntities, 24 | final URLEntity[] urlEntities) { 25 | for (HashtagEntity e : hashtagEntities) { 26 | topics.add(new Hashtag(e.getText())); 27 | } 28 | 29 | for (URLEntity e : urlEntities) { 30 | links.add(new URIReference(e.getURL().toString())); 31 | } 32 | } 33 | 34 | public Entities(final JSONObject json) throws JSONException { 35 | JSONArray urls = json.getJSONArray(TwitterAPI.EntitiesField.URLS.toString()); 36 | for (int i = 0; i < urls.length(); i++) { 37 | JSONObject e = urls.getJSONObject(i); 38 | String text = TwitterAPI.getString(e, TwitterAPI.EntitiesField.EXPANDED_URL); 39 | if (null == text) { 40 | text = TwitterAPI.getString(e, TwitterAPI.EntitiesField.URL); 41 | } 42 | links.add(new URIReference(text)); 43 | } 44 | 45 | JSONArray hashtags = json.getJSONArray(TwitterAPI.EntitiesField.HASHTAGS.toString()); 46 | for (int i = 0; i < hashtags.length(); i++) { 47 | JSONObject e = hashtags.getJSONObject(i); 48 | String text = e.getString(TwitterAPI.EntitiesField.TEXT.toString()).toLowerCase(); 49 | topics.add(new Hashtag(text)); 50 | } 51 | 52 | // Note: USER_MENTIONS field is currently not used. 53 | } 54 | 55 | public Collection getTopics() { 56 | return topics; 57 | } 58 | 59 | public Collection getLinks() { 60 | return links; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/Hashtag.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class Hashtag implements Resource { 7 | private final String name; 8 | 9 | public Hashtag(final String name) { 10 | this.name = name.trim().toLowerCase(); 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public String toString() { 18 | return "#" + name; 19 | } 20 | 21 | public Type getType() { 22 | return Type.HASHTAG; 23 | } 24 | 25 | public boolean equals(final Object other) { 26 | return other instanceof Hashtag 27 | && name.equals(((Hashtag) other).name); 28 | } 29 | 30 | public int hashCode() { 31 | return name.hashCode(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/Person.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class Person implements Resource { 9 | private final User account; 10 | 11 | private Set follows = null; 12 | 13 | public Person(final User account) { 14 | this.account = account; 15 | } 16 | 17 | public Type getType() { 18 | return Type.PERSON; 19 | } 20 | 21 | public User getAccount() { 22 | return account; 23 | } 24 | 25 | public String toString() { 26 | return "[holds:" + account + "]"; 27 | } 28 | 29 | public boolean equals(final Object other) { 30 | return other instanceof Person 31 | && account.equals(((Person) other).account); 32 | } 33 | 34 | public int hashCode() { 35 | return 7 * account.hashCode(); 36 | } 37 | 38 | public Set getFollows() { 39 | return follows; 40 | } 41 | 42 | public void setFollows(Set follows) { 43 | this.follows = follows; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/PlaceType.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | import net.fortytwo.twitlogic.persistence.beans.AdministrativeDivision; 4 | import net.fortytwo.twitlogic.persistence.beans.City; 5 | import net.fortytwo.twitlogic.persistence.beans.Country; 6 | import net.fortytwo.twitlogic.persistence.beans.Neighborhood; 7 | import net.fortytwo.twitlogic.persistence.beans.PointOfInterest; 8 | 9 | /** 10 | * @author Joshua Shinavier (http://fortytwo.net). 11 | */ 12 | public enum PlaceType { 13 | ADMINISTRATIVE_DIVISION("admin", AdministrativeDivision.class), 14 | COUNTRY("country", Country.class), 15 | CITY("city", City.class), 16 | NEIGHBORHOOD("neighborhood", Neighborhood.class), 17 | POINT_OF_INTEREST("poi", PointOfInterest.class); 18 | 19 | private final String name; 20 | private Class elmoClass; 21 | //private final String uri; 22 | 23 | PlaceType(final String name, 24 | final Class elmoClass) { 25 | this.name = name; 26 | this.elmoClass = elmoClass; 27 | //this.uri = uri; 28 | } 29 | 30 | public static PlaceType lookup(final String name) { 31 | for (PlaceType pt : PlaceType.values()) { 32 | if (pt.name.equals(name)) { 33 | return pt; 34 | } 35 | } 36 | 37 | return null; 38 | } 39 | 40 | public Class getElmoClass() { 41 | return elmoClass; 42 | } 43 | 44 | //public String getUri() { 45 | // return uri; 46 | //} 47 | } 48 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/PlainLiteral.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class PlainLiteral implements Resource { 7 | private final String label; 8 | 9 | public PlainLiteral(final String label) { 10 | this.label = label; 11 | } 12 | 13 | public String getLabel() { 14 | return label; 15 | } 16 | 17 | public String toString() { 18 | return "\"" + label + "\""; 19 | } 20 | 21 | public Type getType() { 22 | return Type.PLAIN_LITERAL; 23 | } 24 | 25 | public boolean equals(final Object other) { 26 | return other instanceof PlainLiteral 27 | && label.equals(((PlainLiteral) other).label); 28 | } 29 | 30 | public int hashCode() { 31 | return label.hashCode(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/Resource.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface Resource { 7 | enum Type { 8 | DOLLARTAG, HASHTAG, USER, PERSON, PLAIN_LITERAL, TYPED_LITERAL, URI_REFERENCE, TWEET 9 | } 10 | 11 | Type getType(); 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/Triple.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class Triple { 7 | private final Resource subject; 8 | private final Resource predicate; 9 | private final Resource object; 10 | private final float weight; 11 | 12 | public Triple(final Resource subject, 13 | final Resource predicate, 14 | final Resource object) { 15 | this(subject, predicate, object, 1f); 16 | } 17 | 18 | public Triple(final Resource subject, 19 | final Resource predicate, 20 | final Resource object, 21 | final float weight) { 22 | this.subject = subject; 23 | this.predicate = predicate; 24 | this.object = object; 25 | this.weight = weight; 26 | } 27 | 28 | public Resource getSubject() { 29 | return subject; 30 | } 31 | 32 | public Resource getPredicate() { 33 | return predicate; 34 | } 35 | 36 | public Resource getObject() { 37 | return object; 38 | } 39 | 40 | public String toString() { 41 | StringBuilder sb = new StringBuilder(); 42 | sb.append(subject).append(" "); 43 | sb.append(predicate).append(" "); 44 | sb.append(object); 45 | 46 | return sb.toString(); 47 | } 48 | 49 | public float getWeight() { 50 | return weight; 51 | } 52 | 53 | public boolean equals(final Object other) { 54 | if (other instanceof Triple) { 55 | Triple t = (Triple) other; 56 | return (subject.equals(t.subject) 57 | && predicate.equals(t.predicate) 58 | && object.equals(t.object)); 59 | } else { 60 | return false; 61 | } 62 | } 63 | 64 | public int hashCode() { 65 | return subject.hashCode() + predicate.hashCode() + object.hashCode(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/TweetParseException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class TweetParseException extends Exception { 7 | public TweetParseException(final String msg) { 8 | super(msg); 9 | } 10 | 11 | public TweetParseException(final Throwable cause) { 12 | super(cause); 13 | } 14 | 15 | public TweetParseException(final String msg, 16 | final Throwable cause) { 17 | super(msg, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/TypedLiteral.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class TypedLiteral implements Resource { 7 | private final String label; 8 | private final String datatype; 9 | 10 | public TypedLiteral(final String label, 11 | final String datatype) { 12 | this.label = label; 13 | this.datatype = datatype; 14 | } 15 | 16 | public String getLabel() { 17 | return label; 18 | } 19 | 20 | public String getDatatype() { 21 | return datatype; 22 | } 23 | 24 | public String toString() { 25 | return label; 26 | } 27 | 28 | public Type getType() { 29 | return Type.TYPED_LITERAL; 30 | } 31 | 32 | public boolean equals(final Object other) { 33 | return other instanceof TypedLiteral 34 | && datatype.equals(((TypedLiteral) other).datatype) 35 | && label.equals(((TypedLiteral) other).label); 36 | } 37 | 38 | public int hashCode() { 39 | return label.hashCode() + datatype.hashCode(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/URIReference.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class URIReference implements Resource { 7 | private final String value; 8 | 9 | public Type getType() { 10 | return Type.URI_REFERENCE; 11 | } 12 | 13 | public URIReference(final String value) { 14 | this.value = value; 15 | } 16 | 17 | public String toString() { 18 | return "<" + value + ">"; 19 | } 20 | 21 | public String getValue() { 22 | return value; 23 | } 24 | 25 | public boolean equals(final Object other) { 26 | return other instanceof URIReference 27 | && value.equals(((URIReference) other).value); 28 | } 29 | 30 | public int hashCode() { 31 | return value.hashCode(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/model/geo/Point.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.model.geo; 2 | 3 | import twitter4j.GeoLocation; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class Point { 9 | private final double longitude; 10 | private final double latitude; 11 | 12 | public Point(final GeoLocation l) { 13 | this.longitude = l.getLongitude(); 14 | this.latitude = l.getLatitude(); 15 | } 16 | 17 | public Point(double longitude, double latitude) { 18 | this.longitude = longitude; 19 | this.latitude = latitude; 20 | } 21 | 22 | public String toString() { 23 | return "(" + longitude + ", " + latitude + ")"; 24 | } 25 | 26 | public double getLongitude() { 27 | return longitude; 28 | } 29 | 30 | public double getLatitude() { 31 | return latitude; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/DumpFileGeneratorTask.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | import org.openrdf.rio.RDFFormat; 5 | 6 | import java.io.File; 7 | import java.util.TimerTask; 8 | import java.util.logging.Logger; 9 | 10 | /** 11 | * @author Joshua Shinavier (http://fortytwo.net). 12 | */ 13 | // TODO: add support for N-Quads 14 | public class DumpFileGeneratorTask extends TimerTask { 15 | private static final Logger LOGGER = TwitLogic.getLogger(DumpFileGeneratorTask.class); 16 | 17 | private TweetStore tweetStore; 18 | private final File file; 19 | private final RDFFormat format; 20 | private final boolean compressed; 21 | 22 | public DumpFileGeneratorTask(final TweetStore tweetStore, 23 | final File file, 24 | final RDFFormat format, 25 | final boolean compressed) { 26 | this.tweetStore = tweetStore; 27 | this.file = file; 28 | this.compressed = compressed; 29 | this.format = format; 30 | 31 | file.getParentFile().mkdirs(); 32 | } 33 | 34 | public void run() { 35 | try { 36 | if (compressed) { 37 | tweetStore.dumpToCompressedFile(file, format); 38 | } else { 39 | tweetStore.dumpToFile(file, format); 40 | } 41 | } catch (Throwable t) { 42 | LOGGER.severe("failed to generate dump file: " + t); 43 | t.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/SailFactory.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence; 2 | 3 | import net.fortytwo.twitlogic.util.properties.PropertyException; 4 | import net.fortytwo.twitlogic.util.properties.TypedProperties; 5 | import org.openrdf.sail.Sail; 6 | import org.openrdf.sail.SailException; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public abstract class SailFactory { 12 | protected final TypedProperties conf; 13 | 14 | /** 15 | * 16 | * @param conf configuration properties for the Sail 17 | */ 18 | public SailFactory(final TypedProperties conf) { 19 | this.conf = conf; 20 | } 21 | 22 | /** 23 | * 24 | * @return an initialized Sail 25 | * @throws SailException if there is a problem creating the Sail 26 | * @throws PropertyException if there is a problem reading the configuration 27 | */ 28 | public abstract Sail makeSail() throws SailException, PropertyException; 29 | } 30 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/SimpleTweetContext.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence; 2 | 3 | import net.fortytwo.twitlogic.TweetContext; 4 | import net.fortytwo.twitlogic.model.Person; 5 | import net.fortytwo.twitlogic.model.Resource; 6 | import net.fortytwo.twitlogic.model.Tweet; 7 | import net.fortytwo.twitlogic.model.URIReference; 8 | import net.fortytwo.twitlogic.model.User; 9 | 10 | /** 11 | * @author Joshua Shinavier (http://fortytwo.net). 12 | */ 13 | public class SimpleTweetContext implements TweetContext { 14 | private final Tweet tweet; 15 | 16 | public SimpleTweetContext(final Tweet tweet) { 17 | this.tweet = tweet; 18 | } 19 | 20 | public User thisUser() { 21 | return tweet.getUser(); 22 | } 23 | 24 | public Person thisPerson() { 25 | return thisUser().getHeldBy(); 26 | } 27 | 28 | public User repliedToUser() { 29 | // TODO 30 | throw new IllegalStateException("not implemented"); 31 | } 32 | 33 | public User retweetedUser() { 34 | // TODO 35 | throw new IllegalStateException("not implemented"); 36 | } 37 | 38 | public Tweet thisTweet() { 39 | return tweet; 40 | } 41 | 42 | public Tweet repliedToTweet() { 43 | // TODO 44 | throw new IllegalStateException("not implemented"); 45 | } 46 | 47 | public Resource anonymousNode() { 48 | return new URIReference(SesameTools.createRandomMiscellaneousURIString()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/TweetStoreClient.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence; 2 | 3 | import net.fortytwo.twitlogic.util.CommonHttpClient; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class TweetStoreClient extends CommonHttpClient { 9 | /* 10 | public void dumpTripleStore(final Sail sail, 11 | final String endpointURI) throws TwitterClientException { 12 | HttpClient client = createClient(false); 13 | 14 | HttpUriRequest request = new HttpPost(endpointURI); 15 | 16 | List formParams = new ArrayList(); 17 | formParams.add(new BasicNameValuePair("track", commaDelimit(keywords))); 18 | 19 | setEntity(request, formParams); 20 | 21 | HttpResponse response; 22 | try { 23 | response = client.execute(request); 24 | } catch (IOException e) { 25 | throw new TwitterClientException(e); 26 | } 27 | 28 | if (301 == response.getStatusLine().getStatusCode()) { 29 | return response.getHeaders("Location")[0].getValue(); 30 | } else { 31 | return originalURI; 32 | } 33 | } */ 34 | } 35 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/TweetStoreException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class TweetStoreException extends Exception { 7 | public TweetStoreException(final Throwable cause) { 8 | super(cause); 9 | } 10 | 11 | public TweetStoreException(final String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/UserRegistry.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.model.Tweet; 5 | import net.fortytwo.twitlogic.model.User; 6 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 7 | import net.fortytwo.twitlogic.services.twitter.CustomTwitterClient; 8 | import net.fortytwo.twitlogic.services.twitter.TwitterClientException; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * TODO: make it persistent 15 | * 16 | * @author Joshua Shinavier (http://fortytwo.net). 17 | */ 18 | public class UserRegistry { 19 | private final Map usersByScreenName; 20 | private final CustomTwitterClient client; 21 | 22 | public UserRegistry(final CustomTwitterClient client) { 23 | this.client = client; 24 | usersByScreenName = new HashMap(); 25 | } 26 | 27 | /** 28 | * @param user must contain at least user id and screen name 29 | */ 30 | public void add(final User user) { 31 | if (null == user.getId() || null == user.getScreenName()) { 32 | throw new IllegalArgumentException("null id or screen name"); 33 | } 34 | 35 | if (null == usersByScreenName.get(user.getScreenName())) { 36 | usersByScreenName.put(user.getScreenName(), user); 37 | } 38 | } 39 | 40 | public Long resolveUserId(final String screenName) throws TwitterClientException { 41 | User user = usersByScreenName.get(screenName); 42 | 43 | if (null == user) { 44 | user = client.findUserInfo(screenName); 45 | add(user); 46 | } 47 | 48 | return user.getId(); 49 | } 50 | 51 | public Handler createUserRegistryFilter( 52 | final Handler baseHandler) { 53 | return new Handler() { 54 | public boolean isOpen() { 55 | return baseHandler.isOpen(); 56 | } 57 | 58 | public void handle(final Tweet tweet) throws HandlerException { 59 | add(tweet.getUser()); 60 | baseHandler.handle(tweet); 61 | } 62 | }; 63 | } 64 | 65 | public User findUserInfo(final String screenName) throws TwitterClientException { 66 | User user = client.findUserInfo(screenName); 67 | add(user); 68 | return user; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/AdministrativeDivision.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.DBpediaResource; 4 | import org.openrdf.elmo.annotations.rdf; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | @rdf(DBpediaResource.ADMINISTRATIVE_DIVISION) 10 | public interface AdministrativeDivision extends Feature { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Agent.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import org.openrdf.concepts.owl.Thing; 5 | import org.openrdf.elmo.annotations.inverseOf; 6 | import org.openrdf.elmo.annotations.rdf; 7 | 8 | import java.util.Set; 9 | 10 | /** 11 | * @author Joshua Shinavier (http://fortytwo.net). 12 | */ 13 | @rdf(FOAF.AGENT) 14 | public interface Agent extends Thing { 15 | 16 | @rdf(FOAF.NAME) 17 | String getName(); 18 | void setName(String name); 19 | 20 | @rdf(FOAF.DEPICTION) 21 | Image getDepiction(); 22 | void setDepiction(Image depiction); 23 | 24 | @rdf(FOAF.HOMEPAGE) 25 | Document getHomepage(); 26 | void setHomepage(Document homepage); 27 | 28 | // Note: in terms of Java interfaces and methods, this is a simplification 29 | // of the FOAF ontology for the purpose of this application. However, the 30 | // generated RDF graphs are correct according to the ontology. 31 | @rdf(FOAF.BASEDNEAR) 32 | SpatialThing getBasedNear(); 33 | void setBasedNear(SpatialThing basedNear); 34 | 35 | @rdf(FOAF.KNOWS) 36 | Set getKnows(); 37 | void setKnows(Set knows); 38 | 39 | @inverseOf(FOAF.KNOWS) 40 | Set getKnownBy(); 41 | void setKnownBy(Set knownBy); 42 | } 43 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/City.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.DBpediaResource; 4 | import org.openrdf.elmo.annotations.rdf; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | @rdf(DBpediaResource.CITY) 10 | public interface City extends Feature { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Country.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.DBpediaResource; 4 | import org.openrdf.elmo.annotations.rdf; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | @rdf(DBpediaResource.COUNTRY) 10 | public interface Country extends Feature { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Document.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import org.openrdf.concepts.owl.Thing; 5 | import org.openrdf.elmo.annotations.rdf; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | @rdf(FOAF.DOCUMENT) 11 | public interface Document extends Thing { 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Feature.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.DCTerms; 4 | import net.fortytwo.twitlogic.vocabs.GeoNames; 5 | import org.openrdf.elmo.annotations.rdf; 6 | 7 | import java.util.Set; 8 | 9 | /** 10 | * @author Joshua Shinavier (http://fortytwo.net). 11 | */ 12 | @rdf(GeoNames.FEATURE) 13 | public interface Feature extends SpatialThing { 14 | @rdf(GeoNames.COUNTRYCODE) 15 | String getCountryCode(); 16 | 17 | void setCountryCode(String countryCode); 18 | 19 | @rdf(GeoNames.PARENTFEATURE) 20 | Set getParentFeature(); 21 | 22 | void setParentFeature(Set parentFeature); 23 | 24 | @rdf(DCTerms.TITLE) 25 | String getTitle(); 26 | 27 | void setTitle(String title); 28 | } 29 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Graph.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.RDFG; 4 | import org.openrdf.concepts.owl.Thing; 5 | import org.openrdf.elmo.annotations.rdf; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | @rdf(RDFG.GRAPH) 11 | public interface Graph extends Thing { 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Image.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import org.openrdf.concepts.owl.Thing; 5 | import org.openrdf.elmo.annotations.rdf; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | @rdf(FOAF.IMAGE) 11 | public interface Image extends Thing { 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/MicroblogPost.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.DCTerms; 4 | import net.fortytwo.twitlogic.vocabs.Geo; 5 | import net.fortytwo.twitlogic.vocabs.SIOC; 6 | import net.fortytwo.twitlogic.vocabs.SIOCT; 7 | import org.openrdf.concepts.owl.Thing; 8 | import org.openrdf.elmo.annotations.rdf; 9 | 10 | import javax.xml.datatype.XMLGregorianCalendar; 11 | import java.util.Set; 12 | 13 | /** 14 | * @author Joshua Shinavier (http://fortytwo.net). 15 | */ 16 | @rdf(SIOCT.MICROBLOGPOST) 17 | public interface MicroblogPost extends Thing { 18 | 19 | @rdf(SIOC.EMBEDS_KNOWLEDGE) 20 | Graph getEmbedsKnowledge(); 21 | 22 | void setEmbedsKnowledge(Graph embedsKnowledge); 23 | 24 | @rdf(DCTerms.CREATED) 25 | XMLGregorianCalendar getCreated(); 26 | 27 | void setCreated(XMLGregorianCalendar created); 28 | 29 | @rdf(SIOC.CONTENT) 30 | String getContent(); 31 | 32 | void setContent(String content); 33 | 34 | @rdf(SIOC.HAS_CREATOR) 35 | UserAccount getHasCreator(); 36 | 37 | void setHasCreator(UserAccount hasCreator); 38 | 39 | @rdf(SIOC.REPLY_OF) 40 | MicroblogPost getReplyOf(); 41 | 42 | void setReplyOf(MicroblogPost replyOf); 43 | 44 | @rdf(SIOC.ADDRESSED_TO) 45 | UserAccount getAddressedTo(); 46 | 47 | void setAddressedTo(UserAccount addressedTo); 48 | 49 | @rdf(SIOC.TOPIC) 50 | Set getTopic(); 51 | 52 | void setTopic(Set topic); 53 | 54 | @rdf(SIOC.LINKS_TO) 55 | Set getLinksTo(); 56 | 57 | void setLinksTo(Set linksTo); 58 | 59 | @rdf(Geo.LOCATION) 60 | Set getLocation(); 61 | 62 | void setLocation(Set location); 63 | } 64 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Neighborhood.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.DBpediaResource; 4 | import org.openrdf.elmo.annotations.rdf; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | @rdf(DBpediaResource.NEIGHBORHOOD) 10 | public interface Neighborhood extends Feature { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/Point.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.Geo; 4 | import org.openrdf.elmo.annotations.rdf; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | @rdf(Geo.POINT) 10 | public interface Point extends SpatialThing { 11 | @rdf(Geo.LONG) 12 | double getLong(); 13 | void setLong(double l); 14 | 15 | @rdf(Geo.LAT) 16 | double getLat(); 17 | void setLat(double l); 18 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/PointOfInterest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.DBpediaResource; 4 | import org.openrdf.elmo.annotations.rdf; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | @rdf(DBpediaResource.POINT_OF_INTEREST) 10 | public interface PointOfInterest extends Feature { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/SpatialThing.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import org.openrdf.concepts.owl.Thing; 5 | import org.openrdf.elmo.annotations.rdf; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | @rdf(FOAF.SPATIALTHING) 11 | public interface SpatialThing extends Thing { 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/beans/UserAccount.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.beans; 2 | 3 | import net.fortytwo.twitlogic.vocabs.SIOC; 4 | import org.openrdf.concepts.owl.Thing; 5 | import org.openrdf.elmo.annotations.rdf; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | @rdf(SIOC.USERACCOUNT) 11 | public interface UserAccount extends Thing { 12 | @rdf(SIOC.ID) 13 | String getId(); 14 | 15 | void setId(String id); 16 | 17 | @rdf(SIOC.ACCOUNT_OF) 18 | Agent getAccountOf(); 19 | 20 | void setAccountOf(Agent accountOf); 21 | } 22 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/sail/MemoryStoreFactory.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.sail; 2 | 3 | import net.fortytwo.twitlogic.persistence.SailFactory; 4 | import net.fortytwo.twitlogic.util.properties.PropertyException; 5 | import net.fortytwo.twitlogic.util.properties.TypedProperties; 6 | import net.fortytwo.twitlogic.TwitLogic; 7 | import org.openrdf.sail.Sail; 8 | import org.openrdf.sail.SailException; 9 | import org.openrdf.sail.memory.MemoryStore; 10 | 11 | import java.util.logging.Logger; 12 | 13 | /** 14 | * @author Joshua Shinavier (http://fortytwo.net) 15 | */ 16 | public class MemoryStoreFactory extends SailFactory { 17 | 18 | private static final Logger LOGGER = TwitLogic.getLogger(MemoryStoreFactory.class); 19 | 20 | public MemoryStoreFactory(final TypedProperties conf) { 21 | super(conf); 22 | } 23 | 24 | public Sail makeSail() throws SailException, PropertyException { 25 | LOGGER.info("instantiating MemoryStore"); 26 | 27 | Sail sail = new MemoryStore(); 28 | sail.initialize(); 29 | return sail; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/persistence/sail/NativeStoreFactory.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence.sail; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | import net.fortytwo.twitlogic.persistence.SailFactory; 5 | import net.fortytwo.twitlogic.util.properties.PropertyException; 6 | import net.fortytwo.twitlogic.util.properties.TypedProperties; 7 | import org.openrdf.sail.Sail; 8 | import org.openrdf.sail.SailException; 9 | import org.openrdf.sail.nativerdf.NativeStore; 10 | 11 | import java.io.File; 12 | import java.util.logging.Logger; 13 | 14 | /** 15 | * @author Joshua Shinavier (http://fortytwo.net) 16 | */ 17 | public class NativeStoreFactory extends SailFactory { 18 | 19 | private static final Logger LOGGER = TwitLogic.getLogger(NativeStoreFactory.class); 20 | 21 | public NativeStoreFactory(final TypedProperties conf) { 22 | super(conf); 23 | } 24 | 25 | public Sail makeSail() throws SailException, PropertyException { 26 | File dir = conf.getFile(TwitLogic.NATIVESTORE_DIRECTORY); 27 | String indexes = conf.getString(TwitLogic.NATIVESTORE_INDEXES, null); 28 | 29 | LOGGER.info("instantiating NativeStore in directory: " + dir); 30 | Sail sail = (null == indexes) 31 | ? new NativeStore(dir) 32 | : new NativeStore(dir, indexes.trim()); 33 | sail.initialize(); 34 | 35 | return sail; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/proof/AssumptionStep.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.proof; 2 | 3 | import net.fortytwo.twitlogic.vocabs.Assumption; 4 | import org.openrdf.model.Resource; 5 | import org.openrdf.model.impl.URIImpl; 6 | 7 | /** 8 | * Note: this class refers to an InferenceStep whose inference rule is 9 | * assumption, rather than to the Assumption class itself. 10 | * 11 | * @author Joshua Shinavier (http://fortytwo.net). 12 | */ 13 | public class AssumptionStep extends InferenceStep { 14 | private static final Resource ASSUMPTION 15 | = new URIImpl(Assumption.ASSUMPTION); 16 | 17 | public AssumptionStep(final RDFizerContext context) { 18 | super(ASSUMPTION, null, context); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/proof/InferenceStep.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.proof; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | import net.fortytwo.twitlogic.vocabs.PMLJustification; 6 | import org.openrdf.model.Resource; 7 | import org.openrdf.model.Statement; 8 | import org.openrdf.model.ValueFactory; 9 | import org.openrdf.model.vocabulary.RDF; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class InferenceStep extends PMLConstruct { 15 | private final Resource inferenceRule; 16 | private final NodeSetList antecedentList; 17 | 18 | public InferenceStep(final Resource inferenceRule, 19 | final NodeSetList antecedentList, 20 | final RDFizerContext context) { 21 | super(context); 22 | this.inferenceRule = inferenceRule; 23 | this.antecedentList = antecedentList; 24 | } 25 | 26 | protected void handleStatements(final Handler handler) throws HandlerException { 27 | Resource g = context.getNamedGraph(); 28 | ValueFactory vf = context.getValueFactory(); 29 | 30 | 31 | handler.handle(vf.createStatement( 32 | self, 33 | RDF.TYPE, 34 | vf.createURI(PMLJustification.INFERENCESTEP), 35 | g)); 36 | 37 | handler.handle(vf.createStatement( 38 | self, 39 | vf.createURI(PMLJustification.HASINFERENCERULE), 40 | inferenceRule, 41 | g)); 42 | 43 | if (null == antecedentList) { 44 | handler.handle(vf.createStatement( 45 | self, 46 | vf.createURI(PMLJustification.HASANTECEDENTLIST), 47 | RDF.NIL, 48 | g)); 49 | } else { 50 | handler.handle(vf.createStatement( 51 | self, 52 | vf.createURI(PMLJustification.HASANTECEDENTLIST), 53 | antecedentList.self, 54 | g)); 55 | antecedentList.handleStatements(handler); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/proof/Information.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.proof; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | import net.fortytwo.twitlogic.vocabs.PMLProvenance; 6 | import org.openrdf.model.Resource; 7 | import org.openrdf.model.Statement; 8 | import org.openrdf.model.ValueFactory; 9 | import org.openrdf.model.vocabulary.RDF; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class Information extends PMLConstruct { 15 | private final String rawString; 16 | 17 | public Information(final String rawString, 18 | final RDFizerContext context) { 19 | super(context); 20 | this.rawString = rawString; 21 | } 22 | 23 | protected void handleStatements(final Handler handler) throws HandlerException { 24 | Resource g = context.getNamedGraph(); 25 | ValueFactory vf = context.getValueFactory(); 26 | 27 | handler.handle(vf.createStatement( 28 | self, 29 | RDF.TYPE, 30 | vf.createURI(PMLProvenance.INFORMATION), 31 | g)); 32 | 33 | handler.handle(vf.createStatement( 34 | self, 35 | vf.createURI(PMLProvenance.HASRAWSTRING), 36 | vf.createLiteral(rawString), 37 | g)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/proof/NodeSet.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.proof; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | import net.fortytwo.twitlogic.vocabs.PMLJustification; 6 | import net.fortytwo.twitlogic.vocabs.PMLTrust; 7 | import org.openrdf.model.Resource; 8 | import org.openrdf.model.Statement; 9 | import org.openrdf.model.ValueFactory; 10 | import org.openrdf.model.vocabulary.RDF; 11 | 12 | /** 13 | * @author Joshua Shinavier (http://fortytwo.net). 14 | */ 15 | public class NodeSet extends PMLConstruct { 16 | private final Resource conclusion; 17 | private final Float floatValue; 18 | private final InferenceStep consequentOf; 19 | 20 | public NodeSet(final Resource conclusion, 21 | final Float floatValue, 22 | final InferenceStep consequentOf, 23 | final RDFizerContext context) { 24 | super(context); 25 | this.conclusion = conclusion; 26 | this.floatValue = floatValue; 27 | this.consequentOf = consequentOf; 28 | } 29 | 30 | protected void handleStatements(final Handler handler) throws HandlerException { 31 | Resource g = context.getNamedGraph(); 32 | ValueFactory vf = context.getValueFactory(); 33 | 34 | handler.handle(vf.createStatement( 35 | self, 36 | RDF.TYPE, 37 | vf.createURI(PMLJustification.NODESET), 38 | g)); 39 | 40 | handler.handle(vf.createStatement(self, 41 | vf.createURI(PMLJustification.HASCONCLUSION), 42 | conclusion, 43 | g)); 44 | 45 | if (null != floatValue) { 46 | handler.handle(vf.createStatement( 47 | self, 48 | vf.createURI(PMLTrust.HASFLOATVALUE), 49 | vf.createLiteral(floatValue), 50 | g)); 51 | } 52 | 53 | handler.handle(vf.createStatement(self, 54 | vf.createURI(PMLJustification.ISCONSEQUENTOF), 55 | consequentOf.self, 56 | g)); 57 | consequentOf.handleStatements(handler); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/proof/NodeSetList.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.proof; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | import net.fortytwo.twitlogic.vocabs.PMLJustification; 6 | import org.openrdf.model.Resource; 7 | import org.openrdf.model.Statement; 8 | import org.openrdf.model.ValueFactory; 9 | import org.openrdf.model.vocabulary.RDF; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class NodeSetList extends PMLConstruct { 15 | private final NodeSet first; 16 | private final NodeSetList rest; 17 | 18 | public NodeSetList(final NodeSet first, 19 | final NodeSetList rest, 20 | final RDFizerContext context) { 21 | super(context); 22 | this.first = first; 23 | this.rest = rest; 24 | } 25 | 26 | protected void handleStatements(final Handler handler) throws HandlerException { 27 | Resource g = context.getNamedGraph(); 28 | ValueFactory vf = context.getValueFactory(); 29 | 30 | handler.handle(vf.createStatement( 31 | self, 32 | RDF.TYPE, 33 | vf.createURI(PMLJustification.NODESETLIST), 34 | g)); 35 | 36 | handler.handle(vf.createStatement(self, RDF.FIRST, first.self, g)); 37 | first.handleStatements(handler); 38 | 39 | if (null == rest) { 40 | handler.handle(vf.createStatement(self, RDF.REST, RDF.NIL, g)); 41 | } else { 42 | handler.handle(vf.createStatement(self, RDF.REST, rest.self, g)); 43 | rest.handleStatements(handler); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/proof/PMLConstruct.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.proof; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | import org.openrdf.model.Resource; 6 | import org.openrdf.model.Statement; 7 | import org.openrdf.model.ValueFactory; 8 | 9 | import java.util.Random; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public abstract class PMLConstruct { 15 | private static final Random RANDOM = new Random(); 16 | 17 | protected final Resource self; 18 | protected final RDFizerContext context; 19 | 20 | protected abstract void handleStatements(Handler handler) throws HandlerException; 21 | 22 | protected PMLConstruct(final RDFizerContext context) { 23 | this.context = context; 24 | // TODO: improve this 25 | this.self = context.getValueFactory().createURI( 26 | context.getBaseURI() + RANDOM.nextInt(Integer.MAX_VALUE)); 27 | } 28 | 29 | protected class RDFizerException extends Exception { 30 | public RDFizerException(final Throwable cause) { 31 | super(cause); 32 | } 33 | } 34 | 35 | public class RDFizerContext { 36 | private final String baseURI; 37 | private final ValueFactory valueFactory; 38 | private final Resource namedGraph; 39 | 40 | public RDFizerContext(final String baseURI, 41 | final Resource namedGraph, 42 | final ValueFactory valueFactory) { 43 | this.baseURI = baseURI; 44 | this.namedGraph = namedGraph; 45 | this.valueFactory = valueFactory; 46 | } 47 | 48 | public String getBaseURI() { 49 | return baseURI; 50 | } 51 | 52 | public ValueFactory getValueFactory() { 53 | return valueFactory; 54 | } 55 | 56 | public Resource getNamedGraph() { 57 | return namedGraph; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/proof/Query.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.proof; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | import net.fortytwo.twitlogic.vocabs.PMLJustification; 6 | import net.fortytwo.twitlogic.vocabs.PMLProvenance; 7 | import org.openrdf.model.Resource; 8 | import org.openrdf.model.Statement; 9 | import org.openrdf.model.ValueFactory; 10 | import org.openrdf.model.vocabulary.RDF; 11 | 12 | import java.util.Collection; 13 | 14 | /** 15 | * @author Joshua Shinavier (http://fortytwo.net). 16 | */ 17 | public class Query extends PMLConstruct { 18 | private final Information content; 19 | private final Collection answers; 20 | 21 | public Query(final Information content, 22 | final Collection answers, 23 | final RDFizerContext context) { 24 | super(context); 25 | this.content = content; 26 | this.answers = answers; 27 | } 28 | 29 | protected void handleStatements(final Handler handler) throws HandlerException { 30 | Resource g = context.getNamedGraph(); 31 | ValueFactory vf = context.getValueFactory(); 32 | 33 | handler.handle(vf.createStatement( 34 | self, 35 | RDF.TYPE, 36 | vf.createURI(PMLJustification.QUERY), 37 | g)); 38 | 39 | handler.handle(vf.createStatement( 40 | self, 41 | vf.createURI(PMLProvenance.HASCONTENT), 42 | content.self, 43 | g)); 44 | content.handleStatements(handler); 45 | 46 | for (NodeSet answer : answers) { 47 | handler.handle(vf.createStatement( 48 | self, 49 | vf.createURI(PMLJustification.HASANSWER), 50 | answer.self, 51 | g)); 52 | answer.handleStatements(handler); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/query/Extender.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.query; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public interface Extender { 9 | Collection> findAlternatives(T t); 10 | } 11 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/query/Memo.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.query; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class Memo { 7 | public T target; 8 | public M value; 9 | public double weight; 10 | } 11 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/query/MemoizedRandomWalk.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.query; 2 | 3 | import java.util.Collection; 4 | import java.util.Map; 5 | import java.util.Random; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class MemoizedRandomWalk { 11 | private final Map alternativesByValue; 12 | private final Extender extender; 13 | private final Random random = new Random(); 14 | 15 | public MemoizedRandomWalk(final Map alternativesByValue, 16 | final Extender extender) { 17 | this.alternativesByValue = alternativesByValue; 18 | this.extender = extender; 19 | } 20 | 21 | public Memo chooseRandom(final T t) { 22 | Alternatives alts = alternativesByValue.get(t); 23 | if (null == alts) { 24 | alts = new Alternatives(); 25 | alts.alternatives = extender.findAlternatives(t); 26 | double sum = 0; 27 | for (Memo m : alts.alternatives) { 28 | sum += m.weight; 29 | } 30 | alts.totalWeight = sum; 31 | 32 | alternativesByValue.put(t, alts); 33 | } 34 | 35 | double r = random.nextDouble() * alts.totalWeight; 36 | double sum = 0; 37 | for (Memo m : alts.alternatives) { 38 | sum += m.weight; 39 | if (sum >= r) { 40 | return m; 41 | } 42 | } 43 | 44 | throw new IllegalStateException("failed to choose a random value"); 45 | } 46 | 47 | private class Alternatives { 48 | private double totalWeight; 49 | private Collection> alternatives; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/query/QueryResult.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.query; 2 | 3 | import net.fortytwo.twitlogic.proof.Query; 4 | import org.openrdf.rio.RDFHandler; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class QueryResult { 10 | private final Query answeredQuery; 11 | 12 | public QueryResult(final Query answeredQuery) { 13 | this.answeredQuery = answeredQuery; 14 | } 15 | 16 | public void handleResult(final RDFHandler handler) { 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/ranking/WeightedMatrix.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.ranking; 2 | 3 | import java.util.Collection; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class WeightedMatrix { 12 | private final Map> map; 13 | 14 | public WeightedMatrix() { 15 | map = new HashMap>(); 16 | } 17 | 18 | public Set keySet() { 19 | return map.keySet(); 20 | } 21 | 22 | public Collection> values() { 23 | return map.values(); 24 | } 25 | 26 | public WeightedVector getRow(final A a) { 27 | WeightedVector result = map.get(a); 28 | if (null == result) { 29 | result = new WeightedVector(); 30 | } 31 | return result; 32 | } 33 | 34 | public void addWeight(final A a, final B b, final double weight) { 35 | WeightedVector v = map.get(a); 36 | if (null == v) { 37 | v = new WeightedVector(); 38 | map.put(a, v); 39 | } 40 | v.addWeight(b, weight); 41 | } 42 | 43 | public double getMagnitude() { 44 | double sum = 0; 45 | for (WeightedVector wv : map.values()) { 46 | sum += wv.getMagnitude(); 47 | } 48 | return sum; 49 | } 50 | 51 | public double getWeight(final B b) { 52 | double sum = 0; 53 | for (WeightedVector wv : map.values()) { 54 | sum += wv.getWeight(b); 55 | } 56 | return sum; 57 | } 58 | 59 | public WeightedVector rowNorm() { 60 | WeightedVector sum = new WeightedVector(); 61 | for (WeightedVector wv : map.values()) { 62 | sum = sum.add(wv); 63 | } 64 | return sum; 65 | } 66 | 67 | public WeightedVector columnNorm() { 68 | WeightedVector sum = new WeightedVector(); 69 | for (A a : map.keySet()) { 70 | sum.setWeight(a, map.get(a).getMagnitude()); 71 | } 72 | return sum; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/ranking/WeightedValue.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.ranking; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class WeightedValue implements Comparable> { 7 | public double weight; 8 | public T value; 9 | 10 | public WeightedValue() { 11 | } 12 | 13 | public WeightedValue(final T value, final double weight) { 14 | this.value = value; 15 | this.weight = weight; 16 | } 17 | 18 | public int compareTo(final WeightedValue other) { 19 | return weight < other.weight 20 | ? -1 21 | : weight > other.weight 22 | ? 1 : 0; 23 | } 24 | 25 | public String toString() { 26 | return "WeightedValue(" + weight + ", " + value + ")"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/bitly/BitlyClientException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.bitly; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class BitlyClientException extends Exception { 7 | public BitlyClientException(final Throwable cause) { 8 | super(cause); 9 | } 10 | 11 | public BitlyClientException(final String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/cliqset/CliqsetAPI.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.cliqset; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface CliqsetAPI { 7 | } 8 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/cliqset/CliqsetClient.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.cliqset; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | import net.fortytwo.twitlogic.services.twitter.RestfulJSONClient; 5 | import net.fortytwo.twitlogic.services.twitter.TwitterClientException; 6 | import org.apache.http.client.methods.HttpGet; 7 | import org.json.JSONObject; 8 | 9 | import java.util.Properties; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class CliqsetClient extends RestfulJSONClient { 15 | public static void main(final String[] args) throws Exception { 16 | Properties conf = new Properties(); 17 | conf.setProperty("net.fortytwo.twitlogic.twitter.username", "joshsh1"); 18 | conf.setProperty("net.fortytwo.twitlogic.twitter.password", "testing"); 19 | TwitLogic.setConfiguration(conf); 20 | 21 | CliqsetClient c = new CliqsetClient(); 22 | c.processActivities(); 23 | } 24 | 25 | private void processActivities() throws TwitterClientException { 26 | HttpGet request = new HttpGet("https://api.cliqset.com/200909/activity/joshsh1"); 27 | 28 | JSONObject r = requestJSONObject(request); 29 | System.out.println(r); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/HandlerException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net) 5 | */ 6 | public class HandlerException extends Exception { 7 | public HandlerException(final Throwable cause) { 8 | super(cause); 9 | } 10 | 11 | public HandlerException(final String msg) { 12 | super(msg); 13 | } 14 | 15 | public HandlerException(final String msg, 16 | final Throwable cause) { 17 | super(msg, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/TwitterAPIException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net) 5 | */ 6 | public class TwitterAPIException extends TwitterClientException { 7 | public TwitterAPIException() { 8 | super(); 9 | } 10 | 11 | public TwitterAPIException(final String msg) { 12 | super(msg); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/TwitterAPILimits.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter; 2 | 3 | /** 4 | * See http://apiwiki.twitter.com/Streaming-API-Documentation#statuses/filter 5 | * 6 | * @author Joshua Shinavier (http://fortytwo.net) 7 | */ 8 | public abstract class TwitterAPILimits { 9 | 10 | public abstract int getTimelinePageCountLimit(); 11 | 12 | public abstract int getTrackKeywordsLimit(); 13 | 14 | public abstract int getFollowUserIdsLimit(); 15 | 16 | public abstract int getRestApiRequestsPerHourLimit(); 17 | 18 | /** 19 | * @return at most this many statuses may be retrieved from a timeline via the 'page' and 'count' REST parameters. 20 | */ 21 | public abstract int getStatusesLimit(); 22 | 23 | public static final TwitterAPILimits 24 | DEFAULT_LIMITS, 25 | WHITELIST_LIMITS; 26 | 27 | static { 28 | DEFAULT_LIMITS = new TwitterAPILimits() { 29 | public int getTimelinePageCountLimit() { 30 | return 200; 31 | } 32 | 33 | public int getTrackKeywordsLimit() { 34 | return 200; 35 | } 36 | 37 | public int getFollowUserIdsLimit() { 38 | return 400; 39 | } 40 | 41 | public int getRestApiRequestsPerHourLimit() { 42 | return 150; 43 | } 44 | 45 | public int getStatusesLimit() { 46 | return 3200; 47 | } 48 | }; 49 | 50 | // FIXME: these are not accurate 51 | WHITELIST_LIMITS = new TwitterAPILimits() { 52 | public int getTimelinePageCountLimit() { 53 | return 200; 54 | } 55 | 56 | public int getTrackKeywordsLimit() { 57 | return 200; 58 | } 59 | 60 | public int getFollowUserIdsLimit() { 61 | return 400; 62 | } 63 | 64 | public int getRestApiRequestsPerHourLimit() { 65 | return 150; 66 | } 67 | 68 | public int getStatusesLimit() { 69 | return 3200; 70 | } 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/TwitterClientException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net) 5 | */ 6 | public class TwitterClientException extends Exception { 7 | public TwitterClientException() { 8 | super(); 9 | } 10 | 11 | public TwitterClientException(final Throwable cause) { 12 | super(cause); 13 | } 14 | 15 | public TwitterClientException(final String message) { 16 | super(message); 17 | } 18 | 19 | public TwitterClientException(final String message, 20 | final Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public static class UnauthorizedException extends TwitterClientException { 25 | public UnauthorizedException(final Throwable cause) { 26 | super(cause); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/TwitterConnectionRefusedException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter; 2 | 3 | import org.apache.http.conn.HttpHostConnectException; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net) 7 | */ 8 | public class TwitterConnectionRefusedException extends TwitterClientException { 9 | public TwitterConnectionRefusedException(final HttpHostConnectException e) { 10 | super(e); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/TwitterConnectionResetException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter; 2 | 3 | import java.net.SocketException; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net) 7 | */ 8 | public class TwitterConnectionResetException extends TwitterClientException { 9 | public TwitterConnectionResetException(final SocketException e) { 10 | super(e); 11 | } 12 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/BadGatewayException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 502 Bad Gateway: Twitter is down or being upgraded. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class BadGatewayException extends TwitterAPIException { 11 | } 12 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/BadRequestException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 400 Bad Request: The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class BadRequestException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/EnhanceYourCalmException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 420 Enhance Your Calm: Returned by the Search and Trends API when you are being rate limited. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class EnhanceYourCalmException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/ForbiddenException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 403 Forbidden: The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class ForbiddenException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/InternalServerErrorException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 500 Internal Server Error: Something is broken. Please post to the group so the Twitter team can investigate. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class InternalServerErrorException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/NotAcceptableException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 406 Not Acceptable: Returned by the Search API when an invalid format is specified in the request. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class NotAcceptableException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/NotFoundException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 404 Not Found: The URI requested is invalid or the resource requested, such as a user, does not exists. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class NotFoundException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/NotModifiedException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 304 Not Modified: There was no new data to return. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class NotModifiedException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/ServiceUnavailableException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 503 Service Unavailable: The Twitter servers are up, but overloaded with requests. Try again later. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class ServiceUnavailableException extends TwitterAPIException { 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/errors/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.errors; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPIException; 4 | 5 | /** 6 | * 401 Unauthorized: Authentication credentials were missing or incorrect. 7 | * 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class UnauthorizedException extends TwitterAPIException { 11 | } 12 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/twitter4j/Twitter4jLimits.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.twitter4j; 2 | 3 | import net.fortytwo.twitlogic.services.twitter.TwitterAPILimits; 4 | import twitter4j.RateLimitStatus; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net) 10 | */ 11 | public class Twitter4jLimits extends TwitterAPILimits { 12 | private final Map limits; 13 | 14 | public Twitter4jLimits(final Map limits) { 15 | this.limits = limits; 16 | } 17 | 18 | public int getTimelinePageCountLimit() { 19 | // FIXME 20 | return 1000; 21 | } 22 | 23 | public int getTrackKeywordsLimit() { 24 | // FIXME 25 | return 1000; 26 | } 27 | 28 | public int getFollowUserIdsLimit() { 29 | // FIXME 30 | return 1000; 31 | } 32 | 33 | public int getRestApiRequestsPerHourLimit() { 34 | // FIXME 35 | return 1000; 36 | } 37 | 38 | public int getStatusesLimit() { 39 | // FIXME 40 | return 1000; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/services/twitter/twitter4j/Twitter4jPlay.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter.twitter4j; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | import net.fortytwo.twitlogic.services.twitter.TwitterCredentials; 5 | import twitter4j.Status; 6 | import twitter4j.Twitter; 7 | import twitter4j.TwitterFactory; 8 | import twitter4j.TwitterStream; 9 | import twitter4j.TwitterStreamFactory; 10 | import twitter4j.conf.ConfigurationBuilder; 11 | 12 | import java.io.File; 13 | import java.io.FileInputStream; 14 | import java.util.List; 15 | import java.util.Properties; 16 | 17 | /** 18 | * @author Joshua Shinavier (http://fortytwo.net) 19 | */ 20 | public class Twitter4jPlay { 21 | public static void main(final String[] args) throws Exception { 22 | Properties props = new Properties(); 23 | props.load(new FileInputStream(new File("/tmp/twitlogic.props"))); 24 | TwitLogic.setConfiguration(props); 25 | 26 | TwitterCredentials cred = new TwitterCredentials(); 27 | 28 | ConfigurationBuilder cb = new ConfigurationBuilder(); 29 | cb.setDebugEnabled(true) 30 | .setOAuthConsumerKey(cred.getConsumerKey()) 31 | .setOAuthConsumerSecret(cred.getConsumerSecret()) 32 | .setOAuthAccessToken(cred.getAccessToken()) 33 | .setOAuthAccessTokenSecret(cred.getTokenSecret()); 34 | 35 | TwitterFactory tf = new TwitterFactory(cb.build()); 36 | Twitter twitter = tf.getInstance(); 37 | 38 | List statuses = twitter.getHomeTimeline(); 39 | 40 | System.out.println("Showing friends timeline."); 41 | for (Status status : statuses) { 42 | System.out.println(status.getUser().getName() + ":" + 43 | status.getText()); 44 | } 45 | 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/HashtagLexer.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class HashtagLexer { 12 | private final Lexicon lexicon; 13 | 14 | public HashtagLexer(final Lexicon lexicon) { 15 | this.lexicon = lexicon; 16 | } 17 | 18 | public void tokenize(final String hashtag, 19 | final Handler> resultHandler) throws Exception { 20 | String s = hashtag.trim().toLowerCase(); 21 | if (0 < s.length()) { 22 | tokenize(s, 0, resultHandler, new LinkedList()); 23 | } 24 | } 25 | 26 | private boolean tokenize(final String hashtag, 27 | final int startIndex, 28 | final Handler> resultHandler, 29 | final List completed) throws Exception { 30 | if (hashtag.length() == startIndex) { 31 | boolean b = resultHandler.isOpen(); 32 | if (b) { 33 | resultHandler.handle(completed); 34 | } 35 | return b; 36 | } else { 37 | for (int i = startIndex + 1; i <= hashtag.length(); i++) { 38 | String s = hashtag.substring(startIndex, i); 39 | if (lexicon.isWord(s)) { 40 | completed.add(s); 41 | if (!tokenize(hashtag, i, resultHandler, completed)) { 42 | return false; 43 | } 44 | completed.remove(completed.size() - 1); 45 | } 46 | } 47 | } 48 | 49 | return true; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/Lexicon.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax; 2 | 3 | import java.util.Set; 4 | import java.util.Collection; 5 | import java.util.HashSet; 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.io.BufferedReader; 9 | import java.io.FileReader; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class Lexicon { 15 | private final Set words; 16 | 17 | public Lexicon(final Collection wordList) { 18 | words = new HashSet(); 19 | for (String word : wordList) { 20 | if (0 < word.length()) { 21 | words.add(word); 22 | } 23 | } 24 | } 25 | 26 | // TODO: a basic Unix word list may have to be extended to include plurals, verb tenses, etc. 27 | public Lexicon(final File wordList) throws IOException { 28 | words = new HashSet(); 29 | 30 | BufferedReader r = new BufferedReader(new FileReader(wordList)); 31 | String line; 32 | 33 | while (null != (line = r.readLine())) { 34 | String word = line.trim().toLowerCase(); 35 | if (0 < word.length()) { 36 | words.add(word); 37 | } 38 | } 39 | 40 | r.close(); 41 | } 42 | 43 | public boolean isWord(final String candidate) { 44 | // TODO: normalization may be a waste of time 45 | return words.contains(candidate.trim().toLowerCase()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/Matcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.TweetContext; 5 | import net.fortytwo.twitlogic.model.Triple; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public interface Matcher { 11 | void match(String expression, 12 | Handler handler, 13 | TweetContext context) throws MatcherException; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/MatcherException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class MatcherException extends Exception { 7 | public MatcherException(final Throwable cause) { 8 | super(cause); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/MultiMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax; 2 | 3 | import net.fortytwo.twitlogic.model.Triple; 4 | import net.fortytwo.twitlogic.flow.Handler; 5 | import net.fortytwo.twitlogic.TweetContext; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net). 9 | */ 10 | public class MultiMatcher implements Matcher { 11 | private final Matcher[] componentMatchers; 12 | 13 | public MultiMatcher(final Matcher... componentMatchers) { 14 | this.componentMatchers = componentMatchers; 15 | } 16 | 17 | public void match(final String expression, 18 | final Handler handler, 19 | final TweetContext context) throws MatcherException { 20 | for (Matcher m : componentMatchers) { 21 | m.match(expression, handler, context); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/TopicSniffer.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.model.Entities; 5 | import net.fortytwo.twitlogic.model.Hashtag; 6 | import net.fortytwo.twitlogic.model.Resource; 7 | import net.fortytwo.twitlogic.model.Tweet; 8 | import net.fortytwo.twitlogic.model.URIReference; 9 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 10 | 11 | import java.util.Collection; 12 | 13 | /** 14 | * @author Joshua Shinavier (http://fortytwo.net). 15 | */ 16 | public class TopicSniffer implements Handler { 17 | private final Handler baseHandler; 18 | 19 | public TopicSniffer(final Handler baseHandler) { 20 | this.baseHandler = baseHandler; 21 | } 22 | 23 | public boolean isOpen() { 24 | return baseHandler.isOpen(); 25 | } 26 | 27 | public void handle(final Tweet tweet) throws HandlerException { 28 | if (null == tweet.getEntities() && null != tweet.getText()) { 29 | Entities entities = new Entities(); 30 | 31 | Collection topics = entities.getTopics(); 32 | for (String tag : TweetSyntax.findHashtags(tweet.getText())) { 33 | topics.add(new Hashtag(tag)); 34 | } 35 | 36 | // Note: dollar tags are not "sniffed" here. 37 | 38 | Collection links = entities.getLinks(); 39 | for (String s : TweetSyntax.findLinks(tweet.getText())) { 40 | links.add(new URIReference(s)); 41 | } 42 | 43 | tweet.setEntities(entities); 44 | } 45 | 46 | baseHandler.handle(tweet); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/TweetAnnotator.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.model.Triple; 5 | import net.fortytwo.twitlogic.model.Tweet; 6 | import net.fortytwo.twitlogic.persistence.SimpleTweetContext; 7 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 8 | 9 | /** 10 | * @author Joshua Shinavier (http://fortytwo.net). 11 | */ 12 | public class TweetAnnotator implements Handler { 13 | private final Handler baseHandler; 14 | private final Matcher matcher; 15 | 16 | public TweetAnnotator(final Matcher matcher, 17 | final Handler baseHandler) { 18 | this.matcher = matcher; 19 | this.baseHandler = baseHandler; 20 | } 21 | 22 | public boolean isOpen() { 23 | return baseHandler.isOpen(); 24 | } 25 | 26 | public void handle(final Tweet tweet) throws HandlerException { 27 | Handler tripleHandler = new Handler() { 28 | public boolean isOpen() { 29 | return true; 30 | } 31 | 32 | public void handle(final Triple triple) throws HandlerException { 33 | //System.out.println("got an annotation: " + triple); 34 | tweet.getAnnotations().add(triple); 35 | } 36 | }; 37 | 38 | try { 39 | matcher.match(tweet.getText(), tripleHandler, new SimpleTweetContext(tweet)); 40 | } catch (MatcherException e) { 41 | throw new HandlerException(e); 42 | } 43 | 44 | baseHandler.handle(tweet); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/AfterthoughtContext.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought; 2 | 3 | import net.fortytwo.twitlogic.TweetContext; 4 | import net.fortytwo.twitlogic.flow.Handler; 5 | import net.fortytwo.twitlogic.model.Person; 6 | import net.fortytwo.twitlogic.model.Resource; 7 | import net.fortytwo.twitlogic.model.Triple; 8 | import net.fortytwo.twitlogic.model.Tweet; 9 | import net.fortytwo.twitlogic.model.User; 10 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 11 | 12 | /** 13 | * @author Joshua Shinavier (http://fortytwo.net). 14 | */ 15 | public class AfterthoughtContext implements TweetContext { 16 | private final TweetContext baseContext; 17 | private final Handler handler; 18 | private final Resource subject; 19 | 20 | public AfterthoughtContext(final Resource subject, 21 | final Handler handler, 22 | final TweetContext baseContext) { 23 | this.subject = subject; 24 | this.handler = handler; 25 | this.baseContext = baseContext; 26 | } 27 | 28 | public Resource getSubject() { 29 | return subject; 30 | } 31 | 32 | public void handle(final Triple t) throws HandlerException { 33 | handler.handle(t); 34 | } 35 | 36 | public void handleCompletedTriple(final Resource predicate, 37 | final Resource object) throws HandlerException { 38 | Triple t = new Triple(subject, predicate, object); 39 | handler.handle(t); 40 | } 41 | 42 | public User thisUser() { 43 | return baseContext.thisUser(); 44 | } 45 | 46 | public Person thisPerson() { 47 | return thisUser().getHeldBy(); 48 | } 49 | 50 | public User repliedToUser() { 51 | return baseContext.repliedToUser(); 52 | } 53 | 54 | public User retweetedUser() { 55 | return baseContext.retweetedUser(); 56 | } 57 | 58 | public Tweet thisTweet() { 59 | return baseContext.thisTweet(); 60 | } 61 | 62 | public Tweet repliedToTweet() { 63 | return baseContext.repliedToTweet(); 64 | } 65 | 66 | public Resource anonymousNode() { 67 | return baseContext.anonymousNode(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/AfterthoughtParserHelper.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought; 2 | 3 | import net.fortytwo.twitlogic.model.Resource; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public interface AfterthoughtParserHelper { 9 | void handleAfterthoughtCandidate(Resource subject, 10 | String predicateValueExpression); 11 | } 12 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/CompoundAfterthoughtMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.model.Triple; 5 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 6 | import net.fortytwo.twitlogic.syntax.MatcherException; 7 | 8 | import java.util.Collection; 9 | 10 | /** 11 | * @author Joshua Shinavier (http://fortytwo.net). 12 | */ 13 | public class CompoundAfterthoughtMatcher extends AfterthoughtMatcher { 14 | private final Collection parsers; 15 | 16 | public CompoundAfterthoughtMatcher(Collection parsers) { 17 | this.parsers = parsers; 18 | } 19 | 20 | private class BooleanWrapper { 21 | public boolean value; 22 | } 23 | 24 | protected void matchNormalized(final String normed, 25 | final AfterthoughtContext context) throws MatcherException { 26 | final BooleanWrapper matched = new BooleanWrapper(); 27 | matched.value = false; 28 | 29 | Handler singleMatchHandler = new Handler() { 30 | public boolean isOpen() { 31 | return true; 32 | } 33 | 34 | public void handle(final Triple triple) throws HandlerException { 35 | context.handle(triple); 36 | matched.value = true; 37 | } 38 | }; 39 | 40 | AfterthoughtContext newContext = new AfterthoughtContext( 41 | context.getSubject(), 42 | singleMatchHandler, 43 | context); 44 | 45 | for (AfterthoughtMatcher parser : parsers) { 46 | parser.matchNormalized(normed, newContext); 47 | if (matched.value) { 48 | return; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/DatatypePropertyAfterthoughtMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought; 2 | 3 | import net.fortytwo.twitlogic.model.PlainLiteral; 4 | import net.fortytwo.twitlogic.model.URIReference; 5 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 6 | import net.fortytwo.twitlogic.syntax.MatcherException; 7 | 8 | import java.util.regex.Pattern; 9 | 10 | /** 11 | * @author Joshua Shinavier (http://fortytwo.net). 12 | */ 13 | public abstract class DatatypePropertyAfterthoughtMatcher extends AfterthoughtMatcher { 14 | 15 | protected abstract String propertyURI(); 16 | 17 | protected abstract Pattern predicatePattern(); 18 | 19 | public void matchNormalized(final String normed, 20 | final AfterthoughtContext context) throws MatcherException { 21 | 22 | String[] a = predicatePattern().split(normed); 23 | //System.out.println("a.length = " + a.length); 24 | //System.out.println("a[0] = " + a[0]); 25 | 26 | if (2 == a.length && 0 == a[0].length()) { 27 | String v = a[1].trim(); 28 | if (0 < v.length()) { 29 | try { 30 | context.handleCompletedTriple(new URIReference(propertyURI()), 31 | new PlainLiteral(v)); 32 | } catch (HandlerException e) { 33 | throw new MatcherException(e); 34 | } 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/OwlSameasMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.OWL; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class OwlSameasMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return OWL.SAMEAS; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("same as") 17 | | p.equals("sameas") 18 | | p.equals("=") 19 | | p.equals("aka") 20 | | p.equals("a.k.a.") 21 | | p.equals("ie") 22 | | p.equals("i.e."); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/PmlIsPartOfMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.PML2Relation; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class PmlIsPartOfMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return PML2Relation.ISPARTOF; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("part of") 17 | | p.equals("partof"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/RdfsSeeAlsoMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.RDFS; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class RdfsSeeAlsoMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return RDFS.SEEALSO; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("see"); 17 | } 18 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/contact/AddressMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.contact; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.DatatypePropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.Contact; 5 | 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class AddressMatcher extends DatatypePropertyAfterthoughtMatcher { 12 | private static final Pattern PREDICATE = Pattern.compile("address"); 13 | 14 | protected String propertyURI() { 15 | return Contact.ADDRESS; 16 | } 17 | 18 | protected Pattern predicatePattern() { 19 | return PREDICATE; 20 | } 21 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/contact/BirthdayMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.contact; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.DatatypePropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.Contact; 5 | 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class BirthdayMatcher extends DatatypePropertyAfterthoughtMatcher { 12 | private static final Pattern PREDICATE = Pattern.compile("birthday"); 13 | 14 | protected String propertyURI() { 15 | return Contact.BIRTHDAY; 16 | } 17 | 18 | protected Pattern predicatePattern() { 19 | return PREDICATE; 20 | } 21 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/contact/EmailAddressMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.contact; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.DatatypePropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.Contact; 5 | 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class EmailAddressMatcher extends DatatypePropertyAfterthoughtMatcher { 12 | private static final Pattern PREDICATE = Pattern.compile("email( address)?"); 13 | 14 | protected String propertyURI() { 15 | return Contact.EMAILADDRESS; 16 | } 17 | 18 | protected Pattern predicatePattern() { 19 | return PREDICATE; 20 | } 21 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/contact/FaxMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.contact; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.DatatypePropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.Contact; 5 | 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class FaxMatcher extends DatatypePropertyAfterthoughtMatcher { 12 | private static final Pattern PREDICATE = Pattern.compile("fax( number)?"); 13 | 14 | protected String propertyURI() { 15 | return Contact.FAX; 16 | } 17 | 18 | protected Pattern predicatePattern() { 19 | return PREDICATE; 20 | } 21 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/contact/PhoneMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.contact; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.DatatypePropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.Contact; 5 | 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class PhoneMatcher extends DatatypePropertyAfterthoughtMatcher { 12 | private static final Pattern PREDICATE = Pattern.compile("phone( number)?"); 13 | 14 | protected String propertyURI() { 15 | return Contact.PHONE; 16 | } 17 | 18 | protected Pattern predicatePattern() { 19 | return PREDICATE; 20 | } 21 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/FoafDepictionMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class FoafDepictionMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return FOAF.DEPICTION; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("depiction") 17 | | p.equals("pic") 18 | | p.equals("picture") 19 | | p.equals("pic at:") 20 | | p.equals("pic here:"); 21 | } 22 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/FoafHomepageMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 5 | 6 | /** 7 | * Expression of third-party's interest in a topic. Possibly intrusive (?). 8 | * 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class FoafHomepageMatcher extends ObjectPropertyAfterthoughtMatcher { 12 | protected String getPropertyURI() { 13 | return FOAF.HOMEPAGE; 14 | } 15 | 16 | protected boolean predicateMatches(final String predicate) { 17 | String p = predicate.toLowerCase(); 18 | return p.equals("homepage") | p.equals("home page"); 19 | } 20 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/FoafInterestMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 5 | 6 | /** 7 | * Expression of third-party's interest in a topic. Possibly intrusive (?). 8 | * 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class FoafInterestMatcher extends ObjectPropertyAfterthoughtMatcher { 12 | protected String getPropertyURI() { 13 | return FOAF.INTEREST; 14 | } 15 | 16 | protected boolean predicateMatches(final String predicate) { 17 | String p = predicate.toLowerCase(); 18 | return p.equals("likes") 19 | | p.equals("like"); 20 | } 21 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/FoafKnowsMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class FoafKnowsMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return FOAF.KNOWS; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("knows") 17 | | p.equals("know"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/FoafMadeMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class FoafMadeMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return FOAF.MADE; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("made") 17 | | p.equals("make") 18 | | p.equals("makes") 19 | | p.equals("maker of") 20 | | p.equals("makers of") 21 | | p.equals("created") 22 | | p.equals("creator of") 23 | | p.equals("creators of"); 24 | } 25 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/FoafMakerMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class FoafMakerMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return FOAF.MAKER; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("maker") 17 | | p.equals("creator") 18 | | p.equals("made by") 19 | | p.equals("created by"); 20 | } 21 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/FoafPageMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.vocabs.FOAF; 4 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 5 | 6 | /** 7 | * Expression of third-party's interest in a topic. Possibly intrusive (?). 8 | * 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class FoafPageMatcher extends ObjectPropertyAfterthoughtMatcher { 12 | protected String getPropertyURI() { 13 | return FOAF.PAGE; 14 | } 15 | 16 | protected boolean predicateMatches(final String predicate) { 17 | String p = predicate.toLowerCase(); 18 | return p.equals("page"); 19 | } 20 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/foaf/SelfInterestMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.foaf; 2 | 3 | import net.fortytwo.twitlogic.model.Triple; 4 | import net.fortytwo.twitlogic.model.URIReference; 5 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 6 | import net.fortytwo.twitlogic.syntax.afterthought.AfterthoughtContext; 7 | import net.fortytwo.twitlogic.syntax.afterthought.AfterthoughtMatcher; 8 | import net.fortytwo.twitlogic.syntax.MatcherException; 9 | import net.fortytwo.twitlogic.vocabs.FOAF; 10 | 11 | /** 12 | * Captures "+1" expression of own interest in a topic. 13 | * 14 | * @author Joshua Shinavier (http://fortytwo.net). 15 | */ 16 | public class SelfInterestMatcher extends AfterthoughtMatcher { 17 | public void matchNormalized(final String normed, 18 | final AfterthoughtContext context) throws MatcherException { 19 | if (normed.equals("+1")) { 20 | Triple t = new Triple( 21 | context.thisPerson(), 22 | new URIReference(FOAF.INTEREST), 23 | context.getSubject()); 24 | 25 | try { 26 | context.handle(t); 27 | } catch (HandlerException e) { 28 | throw new MatcherException(e); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/miscellaneous/MentionedBy.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.miscellaneous; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.MiscellaneousVocabs; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class MentionedBy extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return MiscellaneousVocabs.DATAGOVWIKI_NAMESPACE + "mentionedBy"; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("mentioned by"); 17 | } 18 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/openvocab/OVCategoryMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.openvocab; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.OpenVocab; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class OVCategoryMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return OpenVocab.CATEGORY; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("category") 17 | | p.equals("have category") 18 | | p.equals("has category"); 19 | } 20 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/openvocab/OVDepictsMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.openvocab; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.OpenVocab; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class OVDepictsMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return OpenVocab.DEPICTS; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("depicts") 17 | | p.equals("depict"); 18 | } 19 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/openvocab/OVSimilarToMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.openvocab; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.OpenVocab; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class OVSimilarToMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return OpenVocab.SIMILARTO; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("similar to"); 17 | } 18 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/openvocab/OVStudiesMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.openvocab; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.OpenVocab; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class OVStudiesMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return OpenVocab.STUDIES; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("studies") 17 | | p.equals("study"); 18 | } 19 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/openvocab/OVUsesMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.openvocab; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.OpenVocab; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class OVUsesMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return OpenVocab.USES; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("uses") 17 | | p.equals("use"); 18 | } 19 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/skos/SkosBroaderMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.skos; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.SKOS; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class SkosBroaderMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return SKOS.BROADERTRANSITIVE; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("broader") 17 | //| p.equals("=>"); 18 | | p.equals("=>"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/skos/SkosNarrowerMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.skos; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.SKOS; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class SkosNarrowerMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return SKOS.NARROWER; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("narrower") 17 | // | p.equals("<="); 18 | | p.equals("<="); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/afterthought/impl/skos/SkosRelatedMatcher.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl.skos; 2 | 3 | import net.fortytwo.twitlogic.syntax.afterthought.ObjectPropertyAfterthoughtMatcher; 4 | import net.fortytwo.twitlogic.vocabs.SKOS; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class SkosRelatedMatcher extends ObjectPropertyAfterthoughtMatcher { 10 | protected String getPropertyURI() { 11 | return SKOS.RELATED; 12 | } 13 | 14 | protected boolean predicateMatches(final String predicate) { 15 | String p = predicate.toLowerCase(); 16 | return p.equals("related to"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/syntax/twannotations/TwannotationAttributeRdfizer.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.twannotations; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.model.Triple; 5 | import org.json.JSONObject; 6 | 7 | /** 8 | * Note: with the current API, an attribute parser has no awareness of any other attributes in an annotation. 9 | * This may need to be changed, as it is foreseeable that certain attributes are only meaningful in combination with others. 10 | * 11 | * @author Joshua Shinavier (http://fortytwo.net). 12 | */ 13 | public abstract class TwannotationAttributeRdfizer implements Handler { 14 | protected final Handler tripleHandler; 15 | 16 | public TwannotationAttributeRdfizer(final Handler tripleHandler) { 17 | this.tripleHandler = tripleHandler; 18 | } 19 | 20 | public abstract String getFormat(); 21 | } 22 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/Factory.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface Factory { 7 | T create(); 8 | } 9 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/ServerTestApp.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util; 2 | 3 | import net.fortytwo.twitlogic.persistence.TweetStore; 4 | import net.fortytwo.twitlogic.TwitLogic; 5 | import net.fortytwo.twitlogic.services.twitter.TwitterClient; 6 | import net.fortytwo.twitlogic.services.twitter.twitter4j.Twitter4jClient; 7 | 8 | import java.io.FileInputStream; 9 | import java.util.Properties; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class ServerTestApp { 15 | 16 | public static void main(final String[] args) throws Exception { 17 | try { 18 | Properties props = new Properties(); 19 | props.load(new FileInputStream("/Users/josh/projects/fortytwo/twitlogic/config/twitlogic.properties")); 20 | TwitLogic.setConfiguration(props); 21 | 22 | // Create a persistent store. 23 | TweetStore store = new TweetStore(); 24 | store.initialize(); 25 | 26 | try { 27 | TwitterClient client = new Twitter4jClient(); 28 | 29 | // Launch linked data server. 30 | store.startServer(client); 31 | 32 | Object mutex = ""; 33 | synchronized (mutex) { 34 | mutex.wait(); 35 | } 36 | } finally { 37 | store.shutDown(); 38 | } 39 | } catch (Throwable t) { 40 | t.printStackTrace(); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/StoppableHandler.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util; 2 | 3 | import net.fortytwo.twitlogic.flow.Handler; 4 | import net.fortytwo.twitlogic.services.twitter.HandlerException; 5 | 6 | /** 7 | * A convenience object which can be stacked on top of another Handler, 8 | * allowing input to that handler to be stopped. 9 | * 10 | * @author Joshua Shinavier (http://fortytwo.net) 11 | */ 12 | public class StoppableHandler implements Handler { 13 | private final Handler baseHandler; 14 | private boolean stopped = false; 15 | 16 | public StoppableHandler(Handler baseHandler) { 17 | this.baseHandler = baseHandler; 18 | } 19 | 20 | public boolean isOpen() { 21 | return !stopped && baseHandler.isOpen(); 22 | } 23 | 24 | public void handle(T t) throws HandlerException { 25 | baseHandler.handle(t); 26 | } 27 | 28 | public void stop() { 29 | stopped = true; 30 | } 31 | 32 | public void reset() { 33 | stopped = false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/intervals/Interval.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util.intervals; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class Interval> { 7 | public enum IntervalRelation { 8 | PRECEDES, SUCCEEDS, OVERLAPSWITH 9 | } 10 | 11 | private final C start; 12 | private final C end; 13 | 14 | public Interval(final C start, 15 | final C end) { 16 | this.start = start; 17 | this.end = end; 18 | } 19 | 20 | public C getStart() { 21 | return start; 22 | } 23 | 24 | public C getEnd() { 25 | return end; 26 | } 27 | 28 | public IntervalRelation compareTo(final Interval other) { 29 | int startVsStart = start.compareTo(other.start); 30 | 31 | if (startVsStart < 0) { 32 | int endVsStart = end.compareTo(other.start); 33 | 34 | if (endVsStart < 0) { 35 | return IntervalRelation.PRECEDES; 36 | } else { 37 | return IntervalRelation.OVERLAPSWITH; 38 | } 39 | } else { 40 | int startVsEnd = start.compareTo(other.end); 41 | 42 | if (startVsEnd > 0) { 43 | return IntervalRelation.SUCCEEDS; 44 | } else { 45 | return IntervalRelation.OVERLAPSWITH; 46 | } 47 | } 48 | } 49 | 50 | public boolean identicalTo(final Interval other) { 51 | return 0 == this.start.compareTo(other.start) 52 | && 0 == this.end.compareTo(other.end); 53 | } 54 | 55 | public static > Interval merge(final Interval i1, 56 | final Interval i2) { 57 | return new Interval(min(i1.start, i2.start), max(i1.end, i2.end)); 58 | } 59 | 60 | private static > C min(final C d1, final C d2) { 61 | return d1.compareTo(d2) < 0 62 | ? d1 63 | : d2; 64 | } 65 | 66 | private static > C max(final C d1, final C d2) { 67 | return d1.compareTo(d2) > 0 68 | ? d1 69 | : d2; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/intervals/IntervalSequence.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util.intervals; 2 | 3 | import java.util.List; 4 | import java.util.LinkedList; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class IntervalSequence> { 10 | private final List> consecutiveIntervals; 11 | 12 | public IntervalSequence() { 13 | consecutiveIntervals = new LinkedList>(); 14 | } 15 | 16 | public IntervalSequence(final IntervalSequence other) { 17 | consecutiveIntervals = new LinkedList>(); 18 | consecutiveIntervals.addAll(other.consecutiveIntervals); 19 | } 20 | 21 | public void extendTo(final Interval interval) { 22 | for (int i = 0; i < consecutiveIntervals.size(); i++) { 23 | Interval cur = consecutiveIntervals.get(i); 24 | switch (interval.compareTo(cur)) { 25 | case OVERLAPSWITH: 26 | cur = Interval.merge(interval, cur); 27 | while (consecutiveIntervals.size() > i + 1 28 | && cur.compareTo(consecutiveIntervals.get(i + 1)) == Interval.IntervalRelation.OVERLAPSWITH) { 29 | cur = Interval.merge(cur, consecutiveIntervals.get(i + 1)); 30 | consecutiveIntervals.remove(i + 1); 31 | } 32 | consecutiveIntervals.set(i, cur); 33 | return; 34 | case PRECEDES: 35 | consecutiveIntervals.add(i, interval); 36 | return; 37 | } 38 | } 39 | 40 | consecutiveIntervals.add(interval); 41 | } 42 | 43 | public boolean identicalTo(final IntervalSequence other) { 44 | if (this.consecutiveIntervals.size() != other.consecutiveIntervals.size()) { 45 | return false; 46 | } else { 47 | for (int i = 0; i < this.consecutiveIntervals.size(); i++) { 48 | if (!this.consecutiveIntervals.get(i).identicalTo(other.consecutiveIntervals.get(i))) { 49 | return false; 50 | } 51 | } 52 | } 53 | 54 | return true; 55 | } 56 | 57 | public List> getIntervals() { 58 | return consecutiveIntervals; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/properties/InvalidPropertyValueException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util.properties; 2 | 3 | 4 | /** 5 | * @author Joshua Shinavier (http://fortytwo.net). 6 | */ 7 | public class InvalidPropertyValueException extends PropertyException { 8 | public InvalidPropertyValueException(final String propertyName, 9 | final Throwable cause) { 10 | super(propertyName, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/properties/PropertyException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util.properties; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class PropertyException extends Exception { 7 | 8 | public PropertyException(final String propertyName) { 9 | super("for property '" + propertyName + "'"); 10 | } 11 | 12 | public PropertyException(final String propertyName, 13 | final Throwable cause) { 14 | super("for property '" + propertyName + "'", cause); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/util/properties/PropertyValueNotFoundException.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util.properties; 2 | 3 | 4 | /** 5 | * @author Joshua Shinavier (http://fortytwo.net). 6 | */ 7 | public class PropertyValueNotFoundException extends PropertyException { 8 | public PropertyValueNotFoundException(final String propertyName) { 9 | super(propertyName); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/Assumption.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface Assumption { 7 | public static final String NAMESPACE = "http://inference-web.org/registry/DPR/Assumption.owl#"; 8 | 9 | public static final String 10 | ASSUMPTION = NAMESPACE + "Assumption"; 11 | } 12 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/Contact.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface Contact { 7 | public static final String NAMESPACE = "http://www.w3.org/2000/10/swap/pim/contact#"; 8 | 9 | // TODO: classes (the below are all properties) 10 | public static final String 11 | ADDRESS = NAMESPACE + "address", 12 | BIRTHDAY = NAMESPACE + "birthday", 13 | CITY = NAMESPACE + "city", 14 | COUNTRY = NAMESPACE + "country", 15 | DEPARTMENTNAME = NAMESPACE + "departmentName", 16 | EMAILADDRESS = NAMESPACE + "emailAddress", 17 | EMERGENCY = NAMESPACE + "emergency", 18 | FAMILYNAME = NAMESPACE + "familyName", 19 | FAX = NAMESPACE + "fax", 20 | FIRSTNAME = NAMESPACE + "firstName", 21 | GIVENNAME = NAMESPACE + "givenName", 22 | HOME = NAMESPACE + "home", 23 | HOMEPAGE = NAMESPACE + "homePage", 24 | HOMEPAGEADDRESS = NAMESPACE + "homePageAddress", 25 | LASTNAME = NAMESPACE + "lastName", 26 | MAILBOX = NAMESPACE + "mailbox", 27 | MAILBOXURI = NAMESPACE + "mailboxURI", 28 | MIDDLEINITIAL = NAMESPACE + "middleInitial", 29 | MIDDLENAME = NAMESPACE + "middleName", 30 | MOBILE = NAMESPACE + "mobile", 31 | MOTHERTONGUE = NAMESPACE + "motherTongue", 32 | OFFICE = NAMESPACE + "office", 33 | ORGANIZATION = NAMESPACE + "organization", 34 | PARTNER = NAMESPACE + "partner", 35 | PERSONALSUFFIX = NAMESPACE + "personalSuffix", 36 | PERSONALTITLE = NAMESPACE + "personalTitle", 37 | PHONE = NAMESPACE + "phone", 38 | POSTALCODE = NAMESPACE + "postalCode", 39 | PUBLICHOMEPAGE = NAMESPACE + "publicHomePage", 40 | STATEORPROVINCE = NAMESPACE + "stateOrProvince", 41 | STREET = NAMESPACE + "street", 42 | STREET2 = NAMESPACE + "street2", 43 | STREET3 = NAMESPACE + "street3", 44 | TITLE = NAMESPACE + "title", 45 | VACATIONHOME = NAMESPACE + "vacationHome", 46 | ZIP = NAMESPACE + "zip"; 47 | } 48 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/DBpediaResource.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface DBpediaResource { 7 | public static final String BASE_URI = "http://dbpedia.org/resource/"; 8 | 9 | public static final String 10 | ADMINISTRATIVE_DIVISION = BASE_URI + "Administrative_division", 11 | CITY = BASE_URI + "City", 12 | COUNTRY = BASE_URI + "Country", 13 | NEIGHBORHOOD = BASE_URI + "Neighbourhood", // Note: spelled with 'ou' 14 | POINT_OF_INTEREST = BASE_URI + "Point_of_interest"; 15 | } 16 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/DCTerms.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface DCTerms { 7 | public static final String NAMESPACE = "http://purl.org/dc/terms/"; 8 | 9 | public static final String 10 | CREATED = NAMESPACE + "created", 11 | TITLE = NAMESPACE + "title"; 12 | // TODO: other terms 13 | } 14 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/Geo.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public class Geo { 7 | public static final String NAMESPACE = "http://www.w3.org/2003/01/geo/wgs84_pos#"; 8 | 9 | public static final String 10 | ALT = NAMESPACE + "alt", 11 | LAT = NAMESPACE + "lat", 12 | LOCATION = NAMESPACE + "location", 13 | LONG = NAMESPACE + "long", 14 | POINT = NAMESPACE + "Point", 15 | SPATIALTHING = NAMESPACE + "SpatialThing"; 16 | } 17 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/GeoNames.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface GeoNames { 7 | public static final String NAMESPACE = "http://www.geonames.org/ontology#"; 8 | 9 | public static final String 10 | COUNTRYCODE = NAMESPACE + "countryCode", 11 | FEATURE = NAMESPACE + "Feature", 12 | PARENTFEATURE = NAMESPACE + "parentFeature"; 13 | // TODO: other terms 14 | } 15 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/MiscellaneousVocabs.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface MiscellaneousVocabs { 7 | public static final String DATAGOVWIKI_NAMESPACE = "http://data-gov.tw.rpi.edu/vocab/92/"; 8 | } 9 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/OWL.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface OWL { 7 | public static final String NAMESPACE = "http://www.w3.org/2002/07/owl#"; 8 | 9 | // TODO: add other terms 10 | public static final String 11 | SAMEAS = NAMESPACE + "sameAs"; 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/OpenVocab.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface OpenVocab { 7 | public static final String NAMESPACE = "http://open.vocab.org/terms/"; 8 | 9 | public static final String 10 | CATEGORY = NAMESPACE + "category", 11 | DEPICTS = NAMESPACE + "depicts", 12 | SIMILARTO = NAMESPACE + "similarTo", 13 | STUDIES = NAMESPACE + "studies", 14 | USES = NAMESPACE + "uses"; 15 | } 16 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/PML2Relation.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface PML2Relation { 7 | public static final String NAMESPACE = "http://inference-web.org/2.0/pml-relation.owl#"; 8 | 9 | public static final String 10 | ISPARTOF = NAMESPACE + "isPartOf"; 11 | } 12 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/PMLJustification.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface PMLJustification extends PMLProvenance { 7 | public static final String NAMESPACE = "http://inferenceweb.stanford.edu/2006/06/pml-justification.owl#"; 8 | 9 | public static final String 10 | HASANSWER = NAMESPACE + "hasAnswer", 11 | HASANTECEDENTLIST = NAMESPACE + "hasAntecedentList", 12 | HASCONCLUSION = NAMESPACE + "hasConclusion", 13 | HASINFERENCERULE = NAMESPACE + "hasInferenceRule", 14 | INFERENCESTEP = NAMESPACE + "InferenceStep", 15 | ISCONSEQUENTOF = NAMESPACE + "isConsequentOf", 16 | NODESET = NAMESPACE + "NodeSet", 17 | NODESETLIST = NAMESPACE + "NodeSetList", 18 | QUERY = NAMESPACE + "Query"; 19 | } 20 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/PMLProvenance.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface PMLProvenance { 7 | public static final String NAMESPACE = "http://inferenceweb.stanford.edu/2006/06/pml-provenance.owl#"; 8 | 9 | public static final String 10 | HASCONTENT = NAMESPACE + "hasContent", 11 | HASRAWSTRING = NAMESPACE + "hasRawString", 12 | INFERENCERULE = NAMESPACE + "InferenceRule", 13 | INFORMATION = NAMESPACE + "Information"; 14 | } 15 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/PMLTrust.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface PMLTrust extends PMLProvenance { 7 | public static final String NAMESPACE = "http://inferenceweb.stanford.edu/2006/06/pml-trust.owl#"; 8 | 9 | public static final String 10 | FLOATMETRIC = NAMESPACE + "FloatMetric", 11 | HASFLOATVALUE = NAMESPACE + "hasFloatValue"; 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/RDF.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface RDF { 7 | public static final String NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 8 | 9 | public static final String 10 | TYPE = NAMESPACE + "type"; 11 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/RDFG.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface RDFG { 7 | public static final String NAMESPACE = "http://www.w3.org/2004/03/trix/rdfg-1/"; 8 | 9 | public static final String 10 | GRAPH = NAMESPACE + "Graph", 11 | EQUIVALENTGRAPH = NAMESPACE + "equivalentGraph", 12 | SUBGRAPHOF = NAMESPACE + "subGraphOf"; 13 | } 14 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/RDFS.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface RDFS { 7 | public static final String NAMESPACE = "http://www.w3.org/2000/01/rdf-schema#"; 8 | 9 | public static final String 10 | COMMENT = NAMESPACE + "comment", 11 | DOMAIN = NAMESPACE + "domain", 12 | FIRST = NAMESPACE + "first", 13 | ISDEFINEDBY = NAMESPACE + "isDefinedBy", 14 | LABEL = NAMESPACE + "label", 15 | MEMBER = NAMESPACE + "member", 16 | OBJECT = NAMESPACE + "object", 17 | PREDICATE = NAMESPACE + "predicate", 18 | RANGE = NAMESPACE + "range", 19 | REST = NAMESPACE + "rest", 20 | SEEALSO = NAMESPACE + "seeAlso", 21 | SUBCLASSOF = NAMESPACE + "subClassOf", 22 | SUBJECT = NAMESPACE + "subject", 23 | SUBPROPERTYOF = NAMESPACE + "subPropertyOf", 24 | TYPE = NAMESPACE + "type", 25 | VALUE = NAMESPACE + "value"; 26 | } -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/Review.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface Review { 7 | public static final String NAMESPACE = "http://purl.org/stuff/rev#"; 8 | 9 | public static final String 10 | COMMENT = NAMESPACE + "Comment", 11 | COMMENTER = NAMESPACE + "commenter", 12 | FEEDBACK = NAMESPACE + "Feedback", 13 | HASCOMMENT = NAMESPACE + "hasComment", 14 | HASFEEDBACK = NAMESPACE + "hasFeedback", 15 | HASREVIEW = NAMESPACE + "hasReview", 16 | MAXRATING = NAMESPACE + "maxRating", 17 | MINRATING = NAMESPACE + "minRating", 18 | POSITIVEVOTES = NAMESPACE + "positiveVotes", 19 | RATING = NAMESPACE + "rating", 20 | REVIEW = NAMESPACE + "Review", 21 | REVIEWER = NAMESPACE + "reviewer", 22 | TEXT = NAMESPACE + "text", 23 | TITLE = NAMESPACE + "title", 24 | TOTALVOTES = NAMESPACE + "totalVotes", 25 | TYPE = NAMESPACE + "type"; 26 | } 27 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/SIOCT.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface SIOCT { 7 | public static final String NAMESPACE = "http://rdfs.org/sioc/types#"; 8 | 9 | public static final String 10 | MICROBLOGPOST = NAMESPACE + "MicroblogPost"; 11 | } 12 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/SKOS.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface SKOS { 7 | public static final String NAMESPACE = "http://www.w3.org/2004/02/skos/core#"; 8 | 9 | public static final String 10 | BROADER = NAMESPACE + "broader", 11 | BROADERTRANSITIVE = NAMESPACE + "broaderTransitive", 12 | NARROWER = NAMESPACE + "narrower", 13 | NARROWERTRANSITIVE = NAMESPACE + "narrowerTransitive", 14 | RELATED = NAMESPACE + "related"; 15 | } 16 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/SWC.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net). 5 | */ 6 | public interface SWC { 7 | public static final String NAMESPACE = "http://data.semanticweb.org/ns/swc/ontology#"; 8 | 9 | public static final String 10 | IS_SUBEVENT_OF = NAMESPACE + "isSubEventOf", 11 | IS_SUPER_EVENT_OF = NAMESPACE + "isSuperEventOf"; 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/net/fortytwo/twitlogic/vocabs/TwitlogicVocabulary.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.vocabs; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | import org.openrdf.model.URI; 5 | import org.openrdf.model.impl.URIImpl; 6 | 7 | /** 8 | * @author Joshua Shinavier (http://fortytwo.net) 9 | */ 10 | public interface TwitlogicVocabulary { 11 | public static final String 12 | NAMESPACE = "http://fortytwo.net/2009/10/twitlogic#"; 13 | 14 | public static final URI 15 | COVERED_INTERVAL = new URIImpl(NAMESPACE + "coveredInterval"), 16 | TIMESTAMP = new URIImpl(NAMESPACE + "timeStamp"), 17 | START_DATE = new URIImpl(NAMESPACE + "startDate"), 18 | END_DATE = new URIImpl(NAMESPACE + "endDate"), 19 | INTERVAL = new URIImpl(NAMESPACE + "Interval"); 20 | 21 | public static final URI 22 | ASSOCIATION = new URIImpl(NAMESPACE + "Association"), 23 | SUBJECT = new URIImpl(NAMESPACE + "subject"), 24 | OBJECT = new URIImpl(NAMESPACE + "object"), 25 | WORD = new URIImpl(NAMESPACE + "Word"), 26 | WEIGHT = new URIImpl(NAMESPACE + "weight"); 27 | 28 | public static final URI 29 | lastUpdatedAt = new URIImpl(NAMESPACE + "lastUpdatedAt"); 30 | } 31 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/org/jvcompress/lzo/LZOConstants.java: -------------------------------------------------------------------------------- 1 | /* LZOConstants.java -- various constants (Original file) 2 | 3 | This file is part of the LZO real-time data compression library. 4 | 5 | Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer 6 | Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer 7 | Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer 8 | Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer 9 | 10 | The LZO library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU General Public License as 12 | published by the Free Software Foundation; either version 2 of 13 | the License, or (at your option) any later version. 14 | 15 | The LZO library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with the LZO library; see the file COPYING. 22 | If not, write to the Free Software Foundation, Inc., 23 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 24 | 25 | Markus F.X.J. Oberhumer 26 | 27 | http://wildsau.idv.uni-linz.ac.at/mfx/lzo.html 28 | 29 | 30 | Java Porting of minilzo.c (2.03) by 31 | Copyright (C) 2010 Mahadevan Gorti Surya Srinivasa 32 | */ 33 | package org.jvcompress.lzo; 34 | 35 | /*********************************************************************** 36 | * Various constants. 37 | * 38 | * @author Markus F.X.J. Oberhumer 39 | ***********************************************************************/ 40 | /** Constants needed by minilzo 41 | * 42 | * @author mahadevan.gss 43 | */ 44 | 45 | public interface LZOConstants 46 | { 47 | int LZO_E_OK = 0; 48 | int LZO_E_ERROR = -1; 49 | int LZO_E_OUT_OF_MEMORY = -2; 50 | int LZO_E_NOT_COMPRESSIBLE = -3; 51 | int LZO_E_INPUT_OVERRUN = -4; 52 | int LZO_E_OUTPUT_OVERRUN = -5; 53 | int LZO_E_LOOKBEHIND_OVERRUN = -6; 54 | int LZO_E_EOF_NOT_FOUND = -7; 55 | int LZO_E_INPUT_NOT_CONSUMED = -8; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/java/org/jvcompress/util/MInt.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This software is distributed in the hope that it will be useful, 4 | but WITHOUT ANY WARRANTY; without even the implied warranty of 5 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6 | GNU General Public License for more details. 7 | 8 | You should have received a copy of the GNU General Public License; 9 | see the file COPYING. 10 | If not, write to the Free Software Foundation, Inc., 11 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 12 | 13 | Copyright (C) 2010 Mahadevan Gorti Surya Srinivasa 14 | */ 15 | 16 | 17 | /** Mutable integer 18 | * 19 | * @author mahadevan.gss 20 | */ 21 | 22 | package org.jvcompress.util; 23 | public class MInt { 24 | public int v; 25 | 26 | public MInt() { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/python/places/map_places.py: -------------------------------------------------------------------------------- 1 | import json 2 | import urllib2 3 | 4 | def wikipedia_name(name): 5 | w = name.replace(' ', '_') 6 | return w 7 | 8 | f = open('/tmp/new_places-json.txt', 'r') 9 | 10 | for line in f: 11 | try: 12 | o = json.loads(line) 13 | except: 14 | # TODO: output an error message 15 | continue 16 | 17 | place_type = o['place_type'] 18 | name = o['name'] 19 | full_name = o['full_name'] 20 | id = o['id'] 21 | country_code = o['country_code'] 22 | 23 | #if 'US' != country_code: 24 | # print country_code 25 | 26 | q = 'http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=' + urllib2.quote(name) 27 | 28 | response = urllib2.urlopen(q) 29 | text = response.read() 30 | 31 | w = json.loads(text) 32 | a = w[1] 33 | 34 | for p in a: 35 | wn = wikipedia_name(p) 36 | 37 | st = ' owl:sameAs <' + wn + "> . # " + place_type 38 | 39 | wu = 'http://en.wikipedia.org/wiki/' + wn 40 | out = id + '\t' + place_type + '\t' + full_name + '\t' + p + '\t' + wu + '\t' + st 41 | try: 42 | print out 43 | except: 44 | # TODO: output an error message 45 | continue 46 | 47 | 48 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/python/places/map_places.py~: -------------------------------------------------------------------------------- 1 | import json 2 | import urllib2 3 | #from django.utils.encoding import smart_str, smart_unicode 4 | 5 | def wikipedia_name(name): 6 | w = name.replace(' ', '_') 7 | return w 8 | 9 | f = open('/tmp/cities.txt', 'r') 10 | 11 | # f.readline() 12 | 13 | for line in f: 14 | #print line, 15 | o = json.loads(line) 16 | 17 | place_type = o['place_type'] 18 | name = o['name'] 19 | full_name = o['full_name'] 20 | id = o['id'] 21 | country_code = o['country_code'] 22 | 23 | #if 'US' != country_code: 24 | # print country_code 25 | 26 | q = 'http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=' + urllib2.quote(name) 27 | 28 | #print q 29 | 30 | response = urllib2.urlopen(q) 31 | text = response.read() 32 | 33 | #print html 34 | 35 | w = json.loads(text) 36 | a = w[1] 37 | #print a 38 | 39 | for p in a: 40 | wu = 'http://en.wikipedia.org/wiki/' + wikipedia_name(p) 41 | out = id + '\t' + place_type + '\t' + full_name + '\t' + p + '\t' + wu 42 | try: 43 | print out 44 | except: 45 | # do nothing 46 | a = 2 47 | 48 | 49 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/python/places/more_places_mappings.numbers/Contents/PkgInfo: -------------------------------------------------------------------------------- 1 | ???????? -------------------------------------------------------------------------------- /twitlogic-core/src/main/python/places/more_places_mappings.numbers/QuickLook/Thumbnail.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/src/main/python/places/more_places_mappings.numbers/QuickLook/Thumbnail.jpg -------------------------------------------------------------------------------- /twitlogic-core/src/main/python/places/more_places_mappings.numbers/document-thumbnail.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/src/main/python/places/more_places_mappings.numbers/document-thumbnail.tiff -------------------------------------------------------------------------------- /twitlogic-core/src/main/python/places/more_places_mappings.numbers/index.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/src/main/python/places/more_places_mappings.numbers/index.xml.gz -------------------------------------------------------------------------------- /twitlogic-core/src/main/resources/META-INF/services/org.openrdf.query.parser.QueryParserFactory: -------------------------------------------------------------------------------- 1 | org.openrdf.query.parser.sparql.SPARQLParserFactory 2 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/resources/META-INF/services/org.openrdf.rio.RDFParserFactory: -------------------------------------------------------------------------------- 1 | org.openrdf.rio.n3.N3ParserFactory 2 | org.openrdf.rio.nquads.NQuadsParserFactory 3 | org.openrdf.rio.ntriples.NTriplesParserFactory 4 | org.openrdf.rio.rdfxml.RDFXMLParserFactory 5 | org.openrdf.rio.trig.TriGParserFactory 6 | org.openrdf.rio.trix.TriXParserFactory 7 | org.openrdf.rio.turtle.TurtleParserFactory 8 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/resources/META-INF/services/org.openrdf.rio.RDFWriterFactory: -------------------------------------------------------------------------------- 1 | org.openrdf.rio.n3.N3WriterFactory 2 | org.openrdf.rio.nquads.NQuadsWriterFactory 3 | org.openrdf.rio.ntriples.NTriplesWriterFactory 4 | org.openrdf.rio.rdfxml.RDFXMLWriterFactory 5 | org.openrdf.rio.trig.TriGWriterFactory 6 | org.openrdf.rio.trix.TriXWriterFactory 7 | org.openrdf.rio.turtle.TurtleWriterFactory 8 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/resources/net/fortytwo/twitlogic/namespaces.ttl: -------------------------------------------------------------------------------- 1 | # Core W3C vocabularies 2 | @prefix rdf: . 3 | @prefix rdfs: . 4 | @prefix owl: . 5 | @prefix xsd: . 6 | 7 | # Other vocabularies used to represent user-embedded data 8 | @prefix foaf: . 9 | @prefix sioc: . 10 | @prefix rev: . 11 | @prefix sioct: . 12 | 13 | # Vocabularies used for internal purposes. 14 | @prefix rdfg: . 15 | @prefix tl: . 16 | 17 | # Likely to be used in future. 18 | @prefix dc: . 19 | @prefix dcterms: . 20 | @prefix geo: . 21 | @prefix skos: . 22 | -------------------------------------------------------------------------------- /twitlogic-core/src/main/resources/net/fortytwo/twitlogic/twitlogic.example.properties: -------------------------------------------------------------------------------- 1 | # Example TwitLogic configuration 2 | # 3 | # Modify this file appropriately and rename it to twitlogic.properties, 4 | # then re-build the application with Maven. 5 | 6 | 7 | ######################################## 8 | # server 9 | 10 | net.fortytwo.twitlogic.server.baseURI = http://localhost:8182/ 11 | net.fortytwo.twitlogic.server.port = 8182 12 | net.fortytwo.twitlogic.server.staticContentDirectory = /home/you/twitlogic-source/website 13 | 14 | 15 | ######################################## 16 | # persistence 17 | 18 | net.fortytwo.twitlogic.persistence.sailClass = org.openrdf.sail.nativerdf.NativeStore 19 | net.fortytwo.twitlogic.persistence.nativeStoreDirectory = /home/you/writableDirectory/twitlogic-triplestore 20 | 21 | net.fortytwo.twitlogic.persistence.dumpInterval = 300000 22 | 23 | 24 | ######################################## 25 | # Twitter authentication 26 | 27 | # Register a Twitter application at http://twitter.com/oauth_clients 28 | net.fortytwo.twitlogic.twitter.consumerKey = twitterApplicationConsumerKey 29 | net.fortytwo.twitlogic.twitter.consumerSecret = twitterApplicationConsumerSecret 30 | 31 | # Obtained from Twitter via OAuth 32 | net.fortytwo.twitlogic.twitter.accessToken = accessTokenProvidedByTwitter 33 | net.fortytwo.twitlogic.twitter.accessTokenSecret = accessTokenSecretProvidedByTwitter 34 | 35 | # For basic authentication 36 | net.fortytwo.twitlogic.twitter.username = twitterusername 37 | net.fortytwo.twitlogic.twitter.password = password 38 | 39 | 40 | ######################################## 41 | # bit.ly authentication 42 | 43 | # Register for a bit.ly account at http://bit.ly/account/register 44 | net.fortytwo.twitlogic.services.bitly.login = bitlyUserName 45 | net.fortytwo.twitlogic.services.bitly.apiKey = bitlyAPIKey 46 | 47 | 48 | ######################################## 49 | # XMPP clients 50 | 51 | # Register two XMPP clients (e.g. with GTalk) 52 | # Not necessary if you're only running the TwitLogic data aggregator. 53 | net.fortytwo.twitlogic.xmpp.server = example.com 54 | net.fortytwo.twitlogic.xmpp.port = 5222 55 | net.fortytwo.twitlogic.xmpp.reporterUsername = reporter@example.com 56 | net.fortytwo.twitlogic.xmpp.reporterPassword = password 57 | net.fortytwo.twitlogic.xmpp.reasonerUsername = reasoner@example.com 58 | net.fortytwo.twitlogic.xmpp.reasonerPassword = password 59 | 60 | -------------------------------------------------------------------------------- /twitlogic-core/src/test/java/net/fortytwo/twitlogic/SparqlToolsTest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic; 2 | 3 | import net.fortytwo.sesametools.ldserver.query.SparqlTools; 4 | import junit.framework.TestCase; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class SparqlToolsTest extends TestCase { 10 | public void testSparqlResultFormats() throws Exception { 11 | assertEquals(2, SparqlTools.SparqlResultFormat.values().length); 12 | 13 | assertEquals(SparqlTools.SparqlResultFormat.XML, SparqlTools.SparqlResultFormat.values()[0]); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /twitlogic-core/src/test/java/net/fortytwo/twitlogic/TwitLogicTest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic; 2 | 3 | import junit.framework.TestCase; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class TwitLogicTest extends TestCase { 9 | public void testNothing() throws Exception { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /twitlogic-core/src/test/java/net/fortytwo/twitlogic/data/FreeAssociationGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.data; 2 | 3 | import junit.framework.TestCase; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class FreeAssociationGeneratorTest extends TestCase { 9 | public void testNormalizeTerm() throws Exception { 10 | assertEquals("foo", FreeAssociationGenerator.normalizeWord("foo")); 11 | assertEquals("foo", FreeAssociationGenerator.normalizeWord(" foo")); 12 | assertEquals("foo bar", FreeAssociationGenerator.normalizeWord(" \t foo\n\n BAR")); 13 | assertEquals("foo bar quux", FreeAssociationGenerator.normalizeWord(" \t foo\n\n BAR\nqUux \t")); 14 | } 15 | 16 | public void testIsNormalTerm() throws Exception { 17 | assertTrue(FreeAssociationGenerator.isNormalWord("foo")); 18 | assertTrue(FreeAssociationGenerator.isNormalWord("foo bar")); 19 | assertTrue(FreeAssociationGenerator.isNormalWord("a b cee")); 20 | 21 | assertFalse(FreeAssociationGenerator.isNormalWord("")); 22 | assertFalse(FreeAssociationGenerator.isNormalWord(" ab")); 23 | assertFalse(FreeAssociationGenerator.isNormalWord("ab ")); 24 | assertFalse(FreeAssociationGenerator.isNormalWord("Abc")); 25 | assertFalse(FreeAssociationGenerator.isNormalWord("foo23")); 26 | assertFalse(FreeAssociationGenerator.isNormalWord("foo bar")); 27 | assertFalse(FreeAssociationGenerator.isNormalWord("foo\tbar")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /twitlogic-core/src/test/java/net/fortytwo/twitlogic/persistence/SesameToolsTest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.persistence; 2 | 3 | import junit.framework.TestCase; 4 | import org.openrdf.rio.RDFFormat; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net). 8 | */ 9 | public class SesameToolsTest extends TestCase { 10 | public void testRDFFormatByExtension() throws Exception { 11 | /*for (RDFFormat f : RDFFormat.values()) { 12 | System.out.println(f.getDefaultFileExtension() + ": " + f); 13 | }*/ 14 | 15 | assertEquals(RDFFormat.N3, SesameTools.rdfFormatByExtension("n3")); 16 | assertEquals(RDFFormat.NTRIPLES, SesameTools.rdfFormatByExtension("nt")); 17 | assertEquals(RDFFormat.NTRIPLES, SesameTools.rdfFormatByExtension("ntriples")); 18 | assertEquals(RDFFormat.NTRIPLES, SesameTools.rdfFormatByExtension("ntriple")); 19 | assertEquals(RDFFormat.RDFXML, SesameTools.rdfFormatByExtension("rdf")); 20 | assertEquals(RDFFormat.RDFXML, SesameTools.rdfFormatByExtension("rdfxml")); 21 | assertEquals(RDFFormat.TRIG, SesameTools.rdfFormatByExtension("trig")); 22 | assertEquals(RDFFormat.TRIX, SesameTools.rdfFormatByExtension("xml")); 23 | assertEquals(RDFFormat.TRIX, SesameTools.rdfFormatByExtension("trix")); 24 | assertEquals(RDFFormat.TURTLE, SesameTools.rdfFormatByExtension("ttl")); 25 | assertEquals(RDFFormat.TURTLE, SesameTools.rdfFormatByExtension("turtle")); 26 | 27 | // Test case insensitivity. 28 | assertEquals(RDFFormat.TRIG, SesameTools.rdfFormatByExtension("TriG")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /twitlogic-core/src/test/java/net/fortytwo/twitlogic/services/twitter/TwitterAPITest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.services.twitter; 2 | 3 | import junit.framework.TestCase; 4 | 5 | /** 6 | * @author Joshua Shinavier (http://fortytwo.net). 7 | */ 8 | public class TwitterAPITest extends TestCase { 9 | public void testParseTwitterDateString() throws Exception { 10 | // For some reason, parsing once failed on this date string. 11 | TwitterAPI.parseTwitterDateString("Sat May 08 13:21:18 +0000 2010"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /twitlogic-core/src/test/java/net/fortytwo/twitlogic/syntax/afterthought/impl/RdfsSeeAlsoMatcherTest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.syntax.afterthought.impl; 2 | 3 | import net.fortytwo.twitlogic.model.Hashtag; 4 | import net.fortytwo.twitlogic.model.Resource; 5 | import net.fortytwo.twitlogic.model.Triple; 6 | import net.fortytwo.twitlogic.model.URIReference; 7 | import net.fortytwo.twitlogic.syntax.MatcherTestBase; 8 | import net.fortytwo.twitlogic.syntax.afterthought.DemoAfterthoughtMatcher; 9 | import net.fortytwo.twitlogic.vocabs.RDFS; 10 | 11 | /** 12 | * @author Joshua Shinavier (http://fortytwo.net). 13 | */ 14 | public class RdfsSeeAlsoMatcherTest extends MatcherTestBase { 15 | private static final Resource 16 | BRANDX = new Hashtag("brandx"), 17 | BRANDX_URL = new URIReference("http://example.org/brandx"), 18 | SEEALSO = new URIReference(RDFS.SEEALSO); 19 | 20 | 21 | public void setUp() { 22 | matcher = new DemoAfterthoughtMatcher(); 23 | } 24 | 25 | public void testAll() throws Exception { 26 | assertExpected("Just tried out #brandx (see http://example.org/brandx). It's as inferior as they say.", 27 | new Triple(BRANDX, SEEALSO, BRANDX_URL)); 28 | } 29 | } -------------------------------------------------------------------------------- /twitlogic-core/src/test/java/net/fortytwo/twitlogic/util/PolygonTest.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.util; 2 | 3 | import junit.framework.TestCase; 4 | import net.fortytwo.twitlogic.model.geo.Point; 5 | import net.fortytwo.twitlogic.model.geo.Polygon; 6 | import org.json.JSONArray; 7 | 8 | /** 9 | * @author Joshua Shinavier (http://fortytwo.net). 10 | */ 11 | public class PolygonTest extends TestCase { 12 | 13 | public void testDirectionInvariance() throws Exception { 14 | assertCentroid(0.5, 0.5, "[[0,0], [0,1], [1,1], [1,0]]"); 15 | assertCentroid(0.5, 0.5, "[[0,0], [1,0], [1,1], [0,1]]"); 16 | assertCentroid(0.5, 0.5, "[[0,1], [1,1], [1,0], [0,0]]"); 17 | assertCentroid(0.5, 0.5, "[[0,1], [1,1], [1,0], [0,0]]"); 18 | } 19 | 20 | public void testTrivialPolygon() throws Exception { 21 | assertCentroid(0.0, 0.0, "[[0,0], [1,1]]"); 22 | assertCentroid(0.0, 0.0, "[[0,0], [0,0], [0,0], [0,0]]"); 23 | } 24 | 25 | private void assertCentroid(final double lon, 26 | final double lat, 27 | final String json) throws Exception { 28 | Polygon p = new Polygon(new JSONArray(json)); 29 | Point c = p.findCentroid(); 30 | assertEquals(lon, c.getLongitude()); 31 | assertEquals(lat, c.getLatitude()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /twitlogic-core/throughput-testing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find Java 4 | if [ "$JAVA_HOME" = "" ] ; then 5 | JAVA="java" 6 | else 7 | JAVA="$JAVA_HOME/bin/java" 8 | fi 9 | 10 | # Set Java options 11 | if [ "$JAVA_OPTIONS" = "" ] ; then 12 | JAVA_OPTIONS="-Xms32M -Xmx512M -XX:+HeapDumpOnOutOfMemoryError" 13 | fi 14 | 15 | # Launch the application 16 | $JAVA $JAVA_OPTIONS -cp target/classes:"target/dependency/*" net.fortytwo.twitlogic.util.misc.ThroughputTesting $* 17 | 18 | # Return the program's exit code 19 | exit $? 20 | 21 | -------------------------------------------------------------------------------- /twitlogic-core/twitlogic-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find Java 4 | if [ "$JAVA_HOME" = "" ] ; then 5 | JAVA="java" 6 | else 7 | JAVA="$JAVA_HOME/bin/java" 8 | fi 9 | 10 | # Set Java options 11 | if [ "$JAVA_OPTIONS" = "" ] ; then 12 | JAVA_OPTIONS="-Xms32M -Xmx512M" 13 | fi 14 | 15 | # Launch the application 16 | $JAVA $JAVA_OPTIONS -cp target/classes:"target/dependency/*" net.fortytwo.twitlogic.TwitLogicServerDemo $* 17 | 18 | # Return the program's exit code 19 | exit $? 20 | -------------------------------------------------------------------------------- /twitlogic-core/twitlogic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find Java 4 | if [ "$JAVA_HOME" = "" ] ; then 5 | JAVA="java" 6 | else 7 | JAVA="$JAVA_HOME/bin/java" 8 | fi 9 | 10 | # Set Java options 11 | if [ "$JAVA_OPTIONS" = "" ] ; then 12 | JAVA_OPTIONS="-Xms32M -Xmx512M" 13 | fi 14 | 15 | # Launch the application 16 | $JAVA $JAVA_OPTIONS -cp target/classes:"target/dependency/*" net.fortytwo.twitlogic.TwitLogicClientDemo $* 17 | 18 | # Return the program's exit code 19 | exit $? 20 | -------------------------------------------------------------------------------- /twitlogic-core/website/demos/pfizer/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/pfizer/favicon.ico -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/examples/all-tweets.sparql: -------------------------------------------------------------------------------- 1 | # The widget will replace the LIMIT and the time filter with appropriate values. 2 | PREFIX dc: 3 | PREFIX foaf: 4 | PREFIX geo: 5 | PREFIX sioc: 6 | PREFIX xsd: 7 | # Add more namespace definitions as needed 8 | 9 | SELECT DISTINCT ?tweet ?createdAt ?text ?screenName ?profileImage ?place ?placeName WHERE { 10 | ### begin application-specific patterns ### 11 | 12 | #### end application-specific patterns #### 13 | ?tweet dc:created ?createdAt . 14 | ?tweet sioc:content ?text . 15 | ?tweet sioc:has_creator ?account . 16 | ?account sioc:id ?screenName . 17 | ?account sioc:account_of ?agent . 18 | OPTIONAL { ?agent foaf:depiction ?profileImage . } . 19 | OPTIONAL { ?tweet geo:location ?place . 20 | ?place dc:title ?placeName . } . 21 | # TIME FILTER # 22 | } ORDER BY DESC(?createdAt) 23 | # LIMIT # -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/examples/iswc2010-subevents-tweets.sparql: -------------------------------------------------------------------------------- 1 | # The widget will replace the LIMIT and the time filter with appropriate values. 2 | PREFIX dc: 3 | PREFIX foaf: 4 | PREFIX geo: 5 | PREFIX sioc: 6 | PREFIX skos: 7 | PREFIX swc: 8 | PREFIX xsd: 9 | # Add more namespace definitions as needed 10 | PREFIX hashtag: 11 | 12 | SELECT DISTINCT ?tweet ?createdAt ?text ?screenName ?profileImage ?place ?placeName WHERE { 13 | ### begin application-specific patterns ### 14 | swc:isSuperEventOf ?subevent . 15 | ?subevent skos:broader ?topic . 16 | ?tweet sioc:topic ?topic . 17 | #### end application-specific patterns #### 18 | ?tweet dc:created ?createdAt . 19 | ?tweet sioc:content ?text . 20 | ?tweet sioc:has_creator ?account . 21 | ?account sioc:id ?screenName . 22 | ?account sioc:account_of ?agent . 23 | OPTIONAL { ?agent foaf:depiction ?profileImage . } . 24 | OPTIONAL { ?tweet geo:location ?place . 25 | ?place dc:title ?placeName . } . 26 | # TIME FILTER # 27 | } ORDER BY DESC(?createdAt) 28 | # LIMIT # 29 | -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/examples/iswc2010-tweets.sparql: -------------------------------------------------------------------------------- 1 | # The widget will replace the LIMIT and the time filter with appropriate values. 2 | PREFIX dc: 3 | PREFIX foaf: 4 | PREFIX geo: 5 | PREFIX sioc: 6 | PREFIX skos: 7 | PREFIX xsd: 8 | # Add more namespace definitions as needed 9 | PREFIX hashtag: 10 | 11 | SELECT DISTINCT ?tweet ?createdAt ?text ?screenName ?profileImage ?place ?placeName WHERE { 12 | ### begin application-specific patterns ### 13 | skos:broader ?topic . 14 | ?tweet sioc:topic ?topic . 15 | #### end application-specific patterns #### 16 | ?tweet dc:created ?createdAt . 17 | ?tweet sioc:content ?text . 18 | ?tweet sioc:has_creator ?account . 19 | ?account sioc:id ?screenName . 20 | ?account sioc:account_of ?agent . 21 | OPTIONAL { ?agent foaf:depiction ?profileImage . } . 22 | OPTIONAL { ?tweet geo:location ?place . 23 | ?place dc:title ?placeName . } . 24 | # TIME FILTER # 25 | } ORDER BY DESC(?createdAt) 26 | # LIMIT # -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/examples/paper-authors.sparql: -------------------------------------------------------------------------------- 1 | # The widget will replace the LIMIT and the time filter with appropriate values. 2 | PREFIX dc: 3 | PREFIX foaf: 4 | PREFIX geo: 5 | PREFIX owl: 6 | PREFIX sioc: 7 | PREFIX skos: 8 | PREFIX swc: 9 | PREFIX xsd: 10 | # Add more namespace definitions as needed 11 | 12 | SELECT DISTINCT ?tweet ?createdAt ?text ?screenName ?profileImage ?place ?placeName WHERE { 13 | ### begin application-specific patterns ### 14 | { 15 | ?paper swc:isPartOf 16 | } UNION { 17 | ?paper swc:isPartOf ?event . 18 | ?event swc:relatedToEvent . 19 | } 20 | ?author foaf:made ?paper . 21 | ?agent owl:sameAs ?author . 22 | #### end application-specific patterns #### 23 | ?tweet dc:created ?createdAt . 24 | ?tweet sioc:content ?text . 25 | ?tweet sioc:has_creator ?account . 26 | ?account sioc:id ?screenName . 27 | ?account sioc:account_of ?agent . 28 | OPTIONAL { ?agent foaf:depiction ?profileImage . } . 29 | OPTIONAL { ?tweet geo:location ?place . 30 | ?place dc:title ?placeName . } . 31 | # TIME FILTER # 32 | } ORDER BY DESC(?createdAt) 33 | # LIMIT # -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/examples/small_university_towns.sparql: -------------------------------------------------------------------------------- 1 | PREFIX dbprop: 2 | PREFIX dc: 3 | PREFIX foaf: 4 | PREFIX geo: 5 | PREFIX owl: 6 | PREFIX sioc: 7 | PREFIX skos: 8 | PREFIX xsd: 9 | SELECT DISTINCT ?tweet ?createdAt ?text ?screenName ?profileImage ?place ?placeName WHERE { 10 | ### begin application-specific constraints ### 11 | ?tweet geo:location ?place . 12 | ?place owl:sameAs ?dbplace . 13 | ?dbplace skos:subject . 14 | ?dbplace dbprop:populationTotal ?pop . 15 | FILTER(?pop < 50000) . 16 | #### end application-specific constraints #### 17 | ?tweet dc:created ?createdAt . 18 | ?tweet sioc:content ?text . 19 | ?tweet sioc:has_creator ?account . 20 | ?account sioc:id ?screenName . 21 | ?account sioc:account_of ?agent . 22 | OPTIONAL { ?agent foaf:depiction ?profileImage . } . 23 | OPTIONAL { ?tweet geo:location ?place . 24 | ?place dc:title ?placeName . } . 25 | # TIME FILTER # 26 | } 27 | ORDER BY DESC(?createdAt) 28 | # LIMIT # 29 | -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/images/busy-bouncing-white-14x14.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/sparqlwidget/images/busy-bouncing-white-14x14.gif -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/images/footer-sparkle-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/sparqlwidget/images/footer-sparkle-blue.png -------------------------------------------------------------------------------- /twitlogic-core/website/demos/sparqlwidget/images/header-sparkle-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/sparqlwidget/images/header-sparkle-blue.png -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/data/sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "vars": [ 4 | 5 | ] 6 | }, 7 | "results": { 8 | "bindings": [ 9 | { 10 | "o": { 11 | "type": "uri", 12 | "value": "http:\/\/www.w3.org\/2002\/07\/owl#Thing" 13 | }, 14 | "p": { 15 | "type": "uri", 16 | "value": "http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type" 17 | } 18 | }, 19 | { 20 | "o": { 21 | "type": "uri", 22 | "value": "http:\/\/twitlogic.fortytwo.net\/hashtag\/iswc2009" 23 | }, 24 | "p": { 25 | "type": "uri", 26 | "value": "http:\/\/www.w3.org\/2002\/07\/owl#sameAs" 27 | } 28 | }, 29 | { 30 | "o": { 31 | "type": "uri", 32 | "value": "http:\/\/twitlogic.fortytwo.net\/hashtag\/iswc_2009" 33 | }, 34 | "p": { 35 | "type": "uri", 36 | "value": "http:\/\/www.w3.org\/2002\/07\/owl#sameAs" 37 | } 38 | }, 39 | { 40 | "o": { 41 | "type": "uri", 42 | "value": "http:\/\/twitlogic.fortytwo.net\/hashtag\/iswc09" 43 | }, 44 | "p": { 45 | "type": "uri", 46 | "value": "http:\/\/www.w3.org\/2002\/07\/owl#sameAs" 47 | } 48 | }, 49 | { 50 | "o": { 51 | "type": "uri", 52 | "value": "http:\/\/data.semanticweb.org\/conference\/iswc\/2009" 53 | }, 54 | "p": { 55 | "type": "uri", 56 | "value": "http:\/\/www.w3.org\/2002\/07\/owl#sameAs" 57 | } 58 | }, 59 | { 60 | "o": { 61 | "type": "uri", 62 | "value": "http:\/\/twitlogic.fortytwo.net\/hashtag\/iswc" 63 | }, 64 | "p": { 65 | "type": "uri", 66 | "value": "http:\/\/www.w3.org\/2004\/02\/skos\/core#broaderTransitive" 67 | } 68 | } 69 | ] 70 | } 71 | } -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/aboutus-bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/aboutus-bg.gif -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/arrow-closed.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/arrow-closed.gif -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/arrow-open.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/arrow-open.gif -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/close.png -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/content-bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/content-bg.gif -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/logo.png -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/more.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/more.gif -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/ohyeah_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/ohyeah_button.png -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/img/sidebar-bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/demos/twctwit/img/sidebar-bg.gif -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/js/tags.js: -------------------------------------------------------------------------------- 1 | 2 | function _topicLink(uri) { 3 | var a = document.createElement("a"); 4 | a.setAttribute("href", topicTweetsURL(uri)); 5 | a.appendChild(document.createTextNode(abbreviate(uri))); 6 | return a; 7 | } 8 | 9 | function init_tags(uri) { 10 | $.ajax({ 11 | type: "GET", 12 | url: "../../stream/relatedTags", 13 | data: "resource=" + uri, 14 | dataType: "json", 15 | success: function(data) { 16 | var rt = document.getElementById("relatedtags"); 17 | var rt_list = document.getElementById("relatedtags_list"); 18 | 19 | //alert("data.length: " + data.length); 20 | 21 | for (var i = 0; i < data.length; i++) { 22 | var a = _topicLink(data[i]); 23 | 24 | if (0 < i) { 25 | rt_list.appendChild(document.createTextNode(", ")); 26 | } 27 | 28 | rt_list.appendChild(a); 29 | } 30 | 31 | if (0 < data.length) { 32 | rt.style.visibility = "visible"; 33 | } 34 | 35 | /* 36 | if (modaltweets.hasChildNodes()) { 37 | while (modaltweets.childNodes.length >= 1) { 38 | modaltweets.removeChild(modaltweets.firstChild); 39 | } 40 | } 41 | 42 | //alert(data); 43 | var bindings = data.results.bindings; 44 | for (var i = 0; i < bindings.length; i++) { 45 | var b = bindings[i]; 46 | var tweetEl = tweetElement(b); 47 | modaltweets.appendChild(tweetEl); 48 | } 49 | 50 | show_provenance(); 51 | */ 52 | } 53 | }); 54 | } -------------------------------------------------------------------------------- /twitlogic-core/website/demos/twctwit/test.html: -------------------------------------------------------------------------------- 1 |
  • 2 | 3 | 4 | Brian Shaler 6 | 7 | 8 | 9 | 10 | 11 | brianshaler 12 | 13 | 14 |
       16 |
    17 |
    18 | Her: "I don't like being a girl sometimes." Me: "You know, there's an opp for that." 19 |
    20 | 26 |
      27 |
    • 28 | 29 | 30 | Reply 32 | 33 |
    • 34 | 35 |
    • 36 | 37 | 38 | Retweet 39 | 40 |
    • 41 |
    42 |
    43 |
  • -------------------------------------------------------------------------------- /twitlogic-core/website/divider.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/divider.jpg -------------------------------------------------------------------------------- /twitlogic-core/website/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/favicon.ico -------------------------------------------------------------------------------- /twitlogic-core/website/images/TwitLogic_logo_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/images/TwitLogic_logo_large.png -------------------------------------------------------------------------------- /twitlogic-core/website/images/TwitLogic_logo_medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/images/TwitLogic_logo_medium.png -------------------------------------------------------------------------------- /twitlogic-core/website/images/TwitLogic_logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/images/TwitLogic_logo_small.png -------------------------------------------------------------------------------- /twitlogic-core/website/index.css: -------------------------------------------------------------------------------- 1 | #life { 2 | margin: 0; 3 | padding: 0; 4 | color: green; 5 | font-family: Courier; 6 | font-weight: bold; 7 | text-align: center; 8 | } 9 | 10 | #validators { 11 | text-align: center; 12 | } 13 | 14 | div.img { 15 | border: .2em dotted #009; 16 | padding: 5px; 17 | } 18 | 19 | body { 20 | text-align: center; 21 | } 22 | 23 | .content { 24 | margin: 0 auto; 25 | overflow: hidden; 26 | position: relative; 27 | /*word-wrap: break-word; */ 28 | text-align: left; 29 | width: 700px; 30 | } 31 | 32 | .logo { 33 | /* vertical-align: text-top; 34 | text-align: left; */ 35 | float: left; 36 | margin: 5px; 37 | } 38 | 39 | .slideshow { 40 | margin: 0 auto; 41 | overflow: hidden; 42 | position: relative; 43 | /* word-wrap: break-word; */ 44 | text-align: left; 45 | width: 429px; 46 | } 47 | -------------------------------------------------------------------------------- /twitlogic-core/website/josh_email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshsh/twitlogic/60a3ae51ef23bd6e5d7f3932bc649415e4114668/twitlogic-core/website/josh_email.png -------------------------------------------------------------------------------- /twitlogic-core/website/mashup/inc/constants.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /twitlogic-core/website/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: -------------------------------------------------------------------------------- /twitlogic-plugins/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .classpath 3 | .project 4 | .settings 5 | *.iml 6 | *~ 7 | -------------------------------------------------------------------------------- /twitlogic-plugins/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.fortytwo.twitlogic 9 | twitlogic-all 10 | 1.2-SNAPSHOT 11 | 12 | 13 | twitlogic-plugins 14 | pom 15 | TwitLogic Plugins 16 | TwitLogic adapters for other projects and platforms 17 | 18 | 19 | twitlogic-larkc-plugin 20 | 21 | 22 | 23 | ${basedir}/target 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .classpath 3 | .project 4 | .settings 5 | *.iml 6 | *~ 7 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/LICENSE.txt: -------------------------------------------------------------------------------- 1 | TwitLogic LarKC Plugin, Copyright (C) 2010-2011 Joshua Shinavier. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/README.txt: -------------------------------------------------------------------------------- 1 | # Build the plugin 2 | mvn clean install 3 | 4 | # Create TwitLogic configuration properties (including Twitter OAuth credentials) 5 | cp example.properties /tmp/testing.properties 6 | vim /tmp/testing.properties 7 | 8 | # Run the stand-alone demo 9 | java -cp target/twitlogic-larkc-plugin-0.1-full.jar net.fortytwo.twitlogic.larkc.TwitLogicPluginDemo 10 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/TwitLogicPlugin.rdf: -------------------------------------------------------------------------------- 1 | @prefix larkc: . 2 | @prefix rdfs: . 3 | @prefix rdf: . 4 | 5 | larkc:TwitlogicPlugin 6 | rdf:type rdfs:Class ; 7 | rdfs:subClassOf larkc:InformationSetTransformer . 8 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/TwitLogicPlugin.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/example.properties: -------------------------------------------------------------------------------- 1 | ######################################## 2 | # Twitlogic LarKC Plugin 3 | 4 | net.fortytwo.twitlogic.larkc.queueCapacity = 1000 5 | net.fortytwo.twitlogic.larkc.overflowPolicy = DROP_OLDEST 6 | 7 | 8 | ######################################## 9 | # data sources 10 | 11 | net.fortytwo.twitlogic.followUser0 = twit_logic 12 | 13 | net.fortytwo.twitlogic.trackTerms0 = #twitter, #facebook, #foursquare 14 | 15 | 16 | ######################################## 17 | # Twitter authentication 18 | 19 | net.fortytwo.twitlogic.twitter.consumerKey = [consumer key for your Twitter app] 20 | net.fortytwo.twitlogic.twitter.consumerSecret = [consumer secret for your Twitter app] 21 | 22 | net.fortytwo.twitlogic.twitter.accessToken = [access token for your Twitter app and user] 23 | net.fortytwo.twitlogic.twitter.accessTokenSecret = [access token secret for your Twitter app and user] 24 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/assembly/full.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | full 4 | 5 | 6 | jar 7 | 8 | 9 | false 10 | 11 | 12 | 13 | target/classes 14 | / 15 | 16 | 17 | 18 | 19 | 20 | / 21 | true 22 | runtime 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/main/java/net/fortytwo/twitlogic/larkc/SimpleCallback.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.larkc; 2 | 3 | /** 4 | * @author Joshua Shinavier (http://fortytwo.net) 5 | */ 6 | public interface SimpleCallback { 7 | void execute(); 8 | } 9 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/main/java/net/fortytwo/twitlogic/larkc/StatementQueuingListener.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.larkc; 2 | 3 | import net.fortytwo.twitlogic.TwitLogic; 4 | import net.fortytwo.twitlogic.util.properties.PropertyException; 5 | import org.openrdf.model.Statement; 6 | import org.openrdf.sail.SailConnectionListener; 7 | 8 | import java.util.Queue; 9 | import java.util.concurrent.ArrayBlockingQueue; 10 | import java.util.logging.Logger; 11 | 12 | /** 13 | * @author Joshua Shinavier (http://fortytwo.net) 14 | */ 15 | public class StatementQueuingListener implements SailConnectionListener { 16 | 17 | private static final Logger LOGGER = TwitLogic.getLogger(StatementQueuingListener.class); 18 | 19 | private final ArrayBlockingQueue queue; 20 | private final StreamingPlugin.OverflowPolicy policy; 21 | 22 | public StatementQueuingListener(final ArrayBlockingQueue queue, 23 | final StreamingPlugin.OverflowPolicy policy) throws PropertyException { 24 | this.queue = queue; 25 | this.policy = policy; 26 | } 27 | 28 | public void statementAdded(final Statement statement) { 29 | switch (policy) { 30 | case DROP_OLDEST: 31 | while (!queue.offer(statement)) { 32 | try { 33 | queue.take(); 34 | } catch (InterruptedException e) { 35 | LOGGER.severe("thread interrupted while removing from Twitter statement queue"); 36 | } 37 | } 38 | break; 39 | case DROP_MOST_RECENT: 40 | queue.offer(statement); 41 | break; 42 | } 43 | } 44 | 45 | public void statementRemoved(final Statement statement) { 46 | // Do nothing. 47 | } 48 | 49 | public ArrayBlockingQueue getQueue() { 50 | return queue; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/main/java/net/fortytwo/twitlogic/larkc/StreamingPlugin.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.larkc; 2 | 3 | import eu.larkc.plugin.Plugin; 4 | import org.openrdf.model.URI; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net) 8 | */ 9 | public abstract class StreamingPlugin extends Plugin { 10 | public enum OverflowPolicy { DROP_OLDEST, DROP_MOST_RECENT } 11 | 12 | public StreamingPlugin(final URI name) { 13 | super(name); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/main/java/net/fortytwo/twitlogic/larkc/StreamingQueueIterator.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.larkc; 2 | 3 | import eu.larkc.core.data.CloseableIterator; 4 | import org.openrdf.model.Statement; 5 | 6 | import java.util.Queue; 7 | import java.util.concurrent.ArrayBlockingQueue; 8 | 9 | /** 10 | * A CloseableIterator which iterates over the elements of a Queue which is expected to grow indefinitely. 11 | * 12 | * @author Joshua Shinavier (http://fortytwo.net) 13 | */ 14 | public class StreamingQueueIterator implements CloseableIterator { 15 | private final ArrayBlockingQueue queue; 16 | 17 | private Statement n; 18 | private boolean closed = false; 19 | private final SimpleCallback onClose; 20 | 21 | public StreamingQueueIterator(final ArrayBlockingQueue queue, 22 | final SimpleCallback onClose) { 23 | this.queue = queue; 24 | this.onClose = onClose; 25 | } 26 | 27 | public boolean hasNext() { 28 | // A non-closed iterator over a stream always has a next element... it's just a matter of how soon one will become available. 29 | return !closed; 30 | } 31 | 32 | public T next() { 33 | try { 34 | return queue.take(); 35 | } catch (InterruptedException e) { 36 | throw new IllegalStateException(e); 37 | } 38 | } 39 | 40 | public void remove() { 41 | throw new UnsupportedOperationException(); 42 | } 43 | 44 | /** 45 | * Closes this iterator. Note that this does not affect the wrapped queue, 46 | * except insofar as this iterator will no longer be capable of removing elements from it. 47 | */ 48 | public void close() { 49 | if (!closed) { 50 | onClose.execute(); 51 | closed = true; 52 | } 53 | } 54 | 55 | public boolean isClosed() { 56 | return closed; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/main/java/net/fortytwo/twitlogic/larkc/StreamingSetOfStatements.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.larkc; 2 | 3 | 4 | import eu.larkc.core.data.SetOfStatements; 5 | 6 | /** 7 | * @author Joshua Shinavier (http://fortytwo.net) 8 | */ 9 | public abstract class StreamingSetOfStatements implements SetOfStatements { 10 | protected final StreamingPlugin.OverflowPolicy overflowPolicy; 11 | 12 | public StreamingSetOfStatements(final StreamingPlugin.OverflowPolicy overflowPolicy) { 13 | this.overflowPolicy = overflowPolicy; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/main/java/net/fortytwo/twitlogic/larkc/sail/QueueingSail.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.larkc.sail; 2 | 3 | import org.openrdf.model.ValueFactory; 4 | import org.openrdf.sail.Sail; 5 | import org.openrdf.sail.SailConnection; 6 | import org.openrdf.sail.SailConnectionListener; 7 | import org.openrdf.sail.SailException; 8 | import org.openrdf.sail.helpers.SailBase; 9 | import org.openrdf.sail.helpers.SailWrapper; 10 | 11 | /** 12 | * User: josh 13 | * Date: 1/8/11 14 | * Time: 7:43 AM 15 | */ 16 | public class QueueingSail extends SailWrapper { 17 | private final SailConnectionListener listener; 18 | 19 | public QueueingSail(final Sail baseSail, 20 | SailConnectionListener listener) { 21 | super(baseSail); 22 | this.listener = listener; 23 | } 24 | 25 | @Override 26 | public SailConnection getConnection() throws SailException { 27 | return new QueueingSailConnection(this.getBaseSail().getConnection(), listener, this.getValueFactory()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /twitlogic-plugins/twitlogic-larkc-plugin/src/main/java/net/fortytwo/twitlogic/larkc/sail/QueueingSailConnection.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.larkc.sail; 2 | 3 | import org.openrdf.model.Resource; 4 | import org.openrdf.model.Statement; 5 | import org.openrdf.model.URI; 6 | import org.openrdf.model.Value; 7 | import org.openrdf.model.ValueFactory; 8 | import org.openrdf.sail.SailConnection; 9 | import org.openrdf.sail.SailConnectionListener; 10 | import org.openrdf.sail.SailException; 11 | import org.openrdf.sail.helpers.SailConnectionWrapper; 12 | 13 | /** 14 | * User: josh 15 | * Date: 1/8/11 16 | * Time: 7:44 AM 17 | */ 18 | public class QueueingSailConnection extends SailConnectionWrapper { 19 | private static final Resource[] DEFAULT_CONTEXT = {null}; 20 | 21 | private final SailConnectionListener listener; 22 | private final ValueFactory valueFactory; 23 | 24 | public QueueingSailConnection(final SailConnection wrappedCon, 25 | final SailConnectionListener listener, 26 | final ValueFactory valueFactory) { 27 | super(wrappedCon); 28 | this.listener = listener; 29 | this.valueFactory = valueFactory; 30 | } 31 | 32 | @Override 33 | public void addStatement(Resource resource, URI uri, Value value, Resource... resources) throws SailException { 34 | if (0 == resources.length) { 35 | resources = DEFAULT_CONTEXT; 36 | } 37 | 38 | for (Resource c : resources) { 39 | Statement st = valueFactory.createStatement(resource, uri, value, c); 40 | listener.statementAdded(st); 41 | } 42 | 43 | // Elmo needs to be able to retrieve previously added statements, even within a single transaction. 44 | this.getWrappedConnection().addStatement(resource, uri, value, resources); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /twitlogic-rdfagents/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .classpath 3 | .project 4 | .settings 5 | *.iml 6 | *~ 7 | -------------------------------------------------------------------------------- /twitlogic-rdfagents/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.fortytwo.twitlogic 9 | twitlogic-all 10 | 1.2-SNAPSHOT 11 | 12 | 13 | twitlogic-rdfagents 14 | jar 15 | TwitLogic RDFAgents connector 16 | 17 | 18 | 19 | net.fortytwo.rdfagents 20 | rdfagents-jade 21 | ${rdfagents.version} 22 | 23 | 24 | net.fortytwo.twitlogic 25 | twitlogic-core 26 | ${project.version} 27 | 28 | 29 | junit 30 | junit 31 | ${junit.version} 32 | test 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-compiler-plugin 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-source-plugin 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-jar-plugin 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-javadoc-plugin 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-surefire-plugin 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /twitlogic-rdfagents/src/main/java/net/fortytwo/twitlogic/rdfagents/TwitLogicAgent.java: -------------------------------------------------------------------------------- 1 | package net.fortytwo.twitlogic.rdfagents; 2 | 3 | import net.fortytwo.rdfagents.jade.RDFAgentImpl; 4 | import net.fortytwo.rdfagents.jade.SailBasedQueryProvider; 5 | import net.fortytwo.rdfagents.model.AgentId; 6 | import net.fortytwo.rdfagents.model.RDFAgentsPlatform; 7 | 8 | import java.util.Properties; 9 | 10 | /** 11 | * User: josh 12 | * Date: 6/1/11 13 | * Time: 4:25 PM 14 | */ 15 | public class TwitLogicAgent extends RDFAgentImpl { 16 | 17 | private final TwitLogicPubsubProvider pub; 18 | 19 | public TwitLogicAgent(final Properties config, 20 | final RDFAgentsPlatform platform, 21 | final AgentId id) throws RDFAgentException { 22 | super(platform, id); 23 | 24 | try { 25 | pub = new TwitLogicPubsubProvider(this, config); 26 | } catch (Exception e) { 27 | throw new RDFAgentException(e); 28 | } 29 | setPubsubProvider(pub); 30 | 31 | setQueryProvider(new SailBasedQueryProvider(this, pub.getSail())); 32 | } 33 | 34 | public void setRateLimit(final long minimumInterval) { 35 | pub.setMinimumUpdateInterval(minimumInterval); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /twitlogic-rdfagents/src/main/resources/META-INF/services/org.openrdf.rio.RDFParserFactory: -------------------------------------------------------------------------------- 1 | org.openrdf.rio.n3.N3ParserFactory 2 | org.openrdf.rio.ntriples.NTriplesParserFactory 3 | org.openrdf.rio.rdfxml.RDFXMLParserFactory 4 | org.openrdf.rio.trig.TriGParserFactory 5 | org.openrdf.rio.trix.TriXParserFactory 6 | org.openrdf.rio.turtle.TurtleParserFactory 7 | net.fortytwo.sesametools.nquads.NQuadsParserFactory 8 | net.fortytwo.sesametools.rdfjson.RDFJSONParserFactory 9 | -------------------------------------------------------------------------------- /twitlogic-rdfagents/src/main/resources/META-INF/services/org.openrdf.rio.RDFWriterFactory: -------------------------------------------------------------------------------- 1 | org.openrdf.rio.n3.N3WriterFactory 2 | org.openrdf.rio.ntriples.NTriplesWriterFactory 3 | org.openrdf.rio.rdfxml.RDFXMLWriterFactory 4 | org.openrdf.rio.trig.TriGWriterFactory 5 | org.openrdf.rio.trix.TriXWriterFactory 6 | org.openrdf.rio.turtle.TurtleWriterFactory 7 | net.fortytwo.sesametools.nquads.NQuadsWriterFactory 8 | net.fortytwo.sesametools.rdfjson.RDFJSONWriterFactory --------------------------------------------------------------------------------