or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

geographic-data.mdindex.mdinput-format.mdtweet-entities.mdtweet-model.mduser-model.md

tweet-model.mddocs/

0

# Tweet Data Model

1

2

Complete data model representing Twitter's JSON structure with full access to tweet content, user information, engagement metrics, and nested data structures.

3

4

## Capabilities

5

6

### Tweet Class

7

8

Main tweet object containing all tweet data including text content, metadata, user information, and engagement metrics.

9

10

```java { .api }

11

/**

12

* Main Tweet object representing a complete Twitter tweet with all associated data.

13

* Supports nested retweets and provides Kryo serialization compatibility.

14

*/

15

public class Tweet {

16

17

/**

18

* Default constructor creating tweet at nesting level 0

19

*/

20

public Tweet();

21

22

/**

23

* Constructor with specified nesting level for handling retweets

24

* @param level - Nesting level (0 for original tweets, >0 for retweets)

25

*/

26

public Tweet(int level);

27

28

/**

29

* Resets all fields to default values for object reuse

30

* @param level - Nesting level for retweet handling

31

*/

32

public void reset(int level);

33

34

// Core tweet content

35

/**

36

* Gets the tweet text content

37

* @return Tweet text as string

38

*/

39

public String getText();

40

41

/**

42

* Sets the tweet text content

43

* @param text - Tweet text content

44

*/

45

public void setText(String text);

46

47

/**

48

* Gets the unique tweet ID

49

* @return Tweet ID as long

50

*/

51

public long getId();

52

53

/**

54

* Sets the unique tweet ID

55

* @param id - Tweet ID

56

*/

57

public void setId(long id);

58

59

/**

60

* Gets the tweet ID as string

61

* @return Tweet ID as string representation

62

*/

63

public String getId_str();

64

65

/**

66

* Sets the tweet ID as string

67

* @param id_str - Tweet ID as string

68

*/

69

public void setId_str(String id_str);

70

71

/**

72

* Gets the tweet creation timestamp

73

* @return Creation timestamp string in Twitter format

74

*/

75

public String getCreated_at();

76

77

/**

78

* Sets the tweet creation timestamp

79

* @param created_at - Creation timestamp string

80

*/

81

public void setCreated_at(String created_at);

82

83

/**

84

* Gets the tweet source/client information

85

* @return Source string (e.g., "Twitter for iPhone")

86

*/

87

public String getSource();

88

89

/**

90

* Sets the tweet source/client information

91

* @param source - Source string

92

*/

93

public void setSource(String source);

94

95

/**

96

* Gets the tweet language code

97

* @return Language code (e.g., "en", "es")

98

*/

99

public String getLang();

100

101

/**

102

* Sets the tweet language code

103

* @param lang - Language code

104

*/

105

public void setLang(String lang);

106

107

// Engagement metrics

108

/**

109

* Gets the retweet count

110

* @return Number of retweets as long

111

*/

112

public long getRetweet_count();

113

114

/**

115

* Sets the retweet count

116

* @param retweet_count - Number of retweets

117

*/

118

public void setRetweet_count(long retweet_count);

119

120

/**

121

* Gets the favorite/like count

122

* @return Number of favorites as long

123

*/

124

public long getFavorite_count();

125

126

/**

127

* Sets the favorite/like count

128

* @param favorite_count - Number of favorites

129

*/

130

public void setFavorite_count(long favorite_count);

131

132

/**

133

* Checks if the tweet has been retweeted by the current user

134

* @return true if retweeted by current user

135

*/

136

public boolean isRetweeted();

137

138

/**

139

* Sets the retweeted status for current user

140

* @param retweeted - true if retweeted by current user

141

*/

142

public void setRetweeted(boolean retweeted);

143

144

/**

145

* Checks if the tweet has been favorited by the current user

146

* @return true if favorited by current user

147

*/

148

public boolean isFavorited();

149

150

/**

151

* Sets the favorited status for current user

152

* @param favorited - true if favorited by current user

153

*/

154

public void setFavorited(boolean favorited);

155

156

// Tweet metadata

157

/**

158

* Checks if the tweet text was truncated

159

* @return true if tweet text was truncated

160

*/

161

public boolean isTruncated();

162

163

/**

164

* Sets the truncated status

165

* @param truncated - true if tweet text was truncated

166

*/

167

public void setTruncated(boolean truncated);

168

169

/**

170

* Checks if the tweet contains potentially sensitive content

171

* @return true if potentially sensitive

172

*/

173

public boolean getPossibly_sensitive();

174

public boolean isPossibly_sensitive(); // Alternative getter

175

176

/**

177

* Sets the potentially sensitive flag

178

* @param possibly_sensitive - true if potentially sensitive

179

*/

180

public void setPossibly_sensitive(boolean possibly_sensitive);

181

182

/**

183

* Gets the filter level applied to the tweet

184

* @return Filter level string

185

*/

186

public String getFilter_level();

187

188

/**

189

* Sets the filter level

190

* @param filter_level - Filter level string

191

*/

192

public void setFilter_level(String filter_level);

193

194

// Reply information

195

/**

196

* Gets the screen name this tweet is replying to

197

* @return Screen name of replied-to user

198

*/

199

public String getIn_reply_to_screen_name();

200

201

/**

202

* Sets the screen name this tweet is replying to

203

* @param in_reply_to_screen_name - Screen name of replied-to user

204

*/

205

public void setIn_reply_to_screen_name(String in_reply_to_screen_name);

206

207

/**

208

* Gets the status ID this tweet is replying to

209

* @return Status ID of replied-to tweet

210

*/

211

public long getIn_reply_to_status_id();

212

213

/**

214

* Sets the status ID this tweet is replying to

215

* @param in_reply_to_status_id - Status ID of replied-to tweet

216

*/

217

public void setIn_reply_to_status_id(long in_reply_to_status_id);

218

219

/**

220

* Gets the status ID this tweet is replying to as string

221

* @return Status ID string of replied-to tweet

222

*/

223

public String getIn_reply_to_status_id_str();

224

225

/**

226

* Sets the status ID this tweet is replying to as string

227

* @param in_reply_to_status_id_str - Status ID string

228

*/

229

public void setIn_reply_to_status_id_str(String in_reply_to_status_id_str);

230

231

/**

232

* Gets the user ID this tweet is replying to

233

* @return User ID of replied-to user

234

*/

235

public long getIn_reply_to_user_id();

236

237

/**

238

* Sets the user ID this tweet is replying to

239

* @param in_reply_to_user_id - User ID of replied-to user

240

*/

241

public void setIn_reply_to_user_id(long in_reply_to_user_id);

242

243

/**

244

* Gets the user ID this tweet is replying to as string

245

* @return User ID string of replied-to user

246

*/

247

public String getIn_reply_to_user_id_str();

248

249

/**

250

* Sets the user ID this tweet is replying to as string

251

* @param in_reply_to_user_id_str - User ID string

252

*/

253

public void setIn_reply_to_user_id_str(String in_reply_to_user_id_str);

254

255

// Associated objects

256

/**

257

* Gets the user who posted this tweet

258

* @return Users object containing user information

259

*/

260

public Users getUser();

261

262

/**

263

* Sets the user who posted this tweet

264

* @param user - Users object containing user information

265

*/

266

public void setUser(Users user);

267

268

/**

269

* Gets the geographic coordinates of the tweet

270

* @return Coordinates object with longitude/latitude

271

*/

272

public Coordinates getCoordinates();

273

274

/**

275

* Sets the geographic coordinates of the tweet

276

* @param coordinates - Coordinates object

277

*/

278

public void setCoordinates(Coordinates coordinates);

279

280

/**

281

* Gets the place information associated with the tweet

282

* @return Places object containing location data

283

*/

284

public Places getPlace();

285

286

/**

287

* Sets the place information associated with the tweet

288

* @param place - Places object containing location data

289

*/

290

public void setPlace(Places place);

291

292

/**

293

* Gets the extracted entities from the tweet text

294

* @return Entities object containing hashtags, URLs, mentions, etc.

295

*/

296

public Entities getEntities();

297

298

/**

299

* Sets the extracted entities from the tweet text

300

* @param entities - Entities object

301

*/

302

public void setEntities(Entities entities);

303

304

/**

305

* Gets the list of contributors to this tweet

306

* @return List of Contributors objects

307

*/

308

public List<Contributors> getContributors();

309

310

/**

311

* Sets the list of contributors to this tweet

312

* @param contributors - List of Contributors objects

313

*/

314

public void setContributors(List<Contributors> contributors);

315

316

/**

317

* Gets the current user's retweet information

318

* @return CurrentUserRetweet object

319

*/

320

public CurrentUserRetweet getCurrentUserRetweet();

321

322

/**

323

* Sets the current user's retweet information

324

* @param currentUserRetweet - CurrentUserRetweet object

325

*/

326

public void setCurrentUserRetweet(CurrentUserRetweet currentUserRetweet);

327

328

// Retweet handling

329

/**

330

* Gets the original tweet if this is a retweet

331

* @return Tweet object of the original tweet

332

*/

333

public Tweet getRetweeted_status();

334

335

/**

336

* Sets the original tweet if this is a retweet

337

* @param retweeted_status - Original Tweet object

338

*/

339

public void setRetweeted_status(Tweet retweeted_status);

340

341

/**

342

* Gets the nesting level for retweet handling

343

* @return Nesting level as integer

344

*/

345

public int getTweetLevel();

346

347

/**

348

* Sets the nesting level for retweet handling

349

* @param tweetLevel - Nesting level

350

*/

351

public void setTweetLevel(int tweetLevel);

352

}

353

```

354

355

**Usage Examples:**

356

357

```java

358

import org.apache.flink.contrib.tweetinputformat.model.tweet.Tweet;

359

360

// Basic tweet processing

361

Tweet tweet = new Tweet();

362

// Tweet populated by input format...

363

364

// Access tweet content

365

String tweetText = tweet.getText();

366

String author = tweet.getUser().getScreen_name();

367

long retweetCount = tweet.getRetweet_count();

368

369

System.out.println(author + " tweeted: " + tweetText);

370

System.out.println("Retweets: " + retweetCount);

371

372

// Check for replies

373

if (tweet.getIn_reply_to_screen_name() != null) {

374

System.out.println("Reply to: " + tweet.getIn_reply_to_screen_name());

375

}

376

377

// Process hashtags from entities

378

tweet.getEntities().getHashtags().forEach(hashtag -> {

379

System.out.println("Hashtag: #" + hashtag.getText());

380

});

381

382

// Handle retweets

383

if (tweet.getRetweeted_status() != null) {

384

Tweet originalTweet = tweet.getRetweeted_status();

385

System.out.println("Original tweet by: " + originalTweet.getUser().getScreen_name());

386

System.out.println("Original text: " + originalTweet.getText());

387

}

388

```

389

390

```java

391

// Filter and transform tweets

392

DataSet<Tweet> tweets = env.readFile(new SimpleTweetInputFormat(), "tweets.json");

393

394

// Extract high-engagement tweets

395

DataSet<Tweet> popularTweets = tweets.filter(tweet ->

396

tweet.getRetweet_count() > 100 || tweet.getFavorite_count() > 500

397

);

398

399

// Get tweet summaries

400

DataSet<String> tweetSummaries = tweets.map(tweet -> {

401

return String.format("@%s (%s): %s [RT:%d, Fav:%d]",

402

tweet.getUser().getScreen_name(),

403

tweet.getCreated_at(),

404

tweet.getText().substring(0, Math.min(50, tweet.getText().length())),

405

tweet.getRetweet_count(),

406

tweet.getFavorite_count()

407

);

408

});

409

```

410

411

**Key Features:**

412

413

- **Complete Twitter JSON Schema**: Represents all fields from Twitter REST API v1.1

414

- **Nested Object Support**: Full access to user, entities, places, and coordinate data

415

- **Retweet Handling**: Proper nesting support for retweeted status objects

416

- **Kryo Serialization**: Compatible with Flink's serialization system

417

- **Object Reuse**: Reset functionality for memory-efficient processing

418

- **Type Safety**: Strongly-typed access to all tweet properties