or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

entity-parsing.mdgeographic-data.mdindex.mdinput-format.mdtweet-model.mduser-model.md

tweet-model.mddocs/

0

# Tweet Data Model

1

2

Complete Twitter data model with `Tweet` as the root entity, containing all standard Twitter API fields including user information, entities, geographic data, and engagement metrics.

3

4

## Capabilities

5

6

### Tweet Class

7

8

Main tweet data structure representing a complete Twitter tweet with all associated metadata, relationships, and engagement information.

9

10

```java { .api }

11

/**

12

* Represents a complete Twitter tweet with all associated data.

13

* Supports nested retweets and optimized for Flink serialization.

14

*/

15

public class Tweet {

16

17

/**

18

* Default constructor creating a level 0 tweet (supports nested retweets).

19

*/

20

public Tweet();

21

22

/**

23

* Constructor with 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

* Reset all fields for object reuse (Kryo serialization optimization).

30

* @param level Nesting level for retweet handling

31

*/

32

public void reset(int level);

33

34

// Core tweet content

35

/**

36

* Get the text content of the tweet.

37

* @return Tweet text content

38

*/

39

public String getText();

40

41

/**

42

* Set the text content of the tweet.

43

* @param text Tweet text content

44

*/

45

public void setText(String text);

46

47

/**

48

* Get the unique identifier of the tweet.

49

* @return Tweet ID as long

50

*/

51

public long getId();

52

53

/**

54

* Set the unique identifier of the tweet.

55

* @param id Tweet ID as long

56

*/

57

public void setId(long id);

58

59

/**

60

* Get the string representation of the tweet ID.

61

* @return Tweet ID as string

62

*/

63

public String getId_str();

64

65

/**

66

* Set the string representation of the tweet ID.

67

* @param id_str Tweet ID as string

68

*/

69

public void setId_str(String id_str);

70

71

/**

72

* Get the creation timestamp of the tweet.

73

* @return Creation timestamp in Twitter format

74

*/

75

public String getCreated_at();

76

77

/**

78

* Set the creation timestamp of the tweet.

79

* @param created_at Creation timestamp in Twitter format

80

*/

81

public void setCreated_at(String created_at);

82

83

/**

84

* Get the source application that created the tweet.

85

* @return Source application name/link

86

*/

87

public String getSource();

88

89

/**

90

* Set the source application that created the tweet.

91

* @param source Source application name/link

92

*/

93

public void setSource(String source);

94

95

/**

96

* Check if the tweet text is truncated.

97

* @return true if truncated

98

*/

99

public boolean isTruncated();

100

101

/**

102

* Set whether the tweet text is truncated.

103

* @param truncated true if truncated

104

*/

105

public void setTruncated(boolean truncated);

106

107

// Reply information

108

/**

109

* Get the screen name this tweet is replying to.

110

* @return Screen name or empty string

111

*/

112

public String getIn_reply_to_screen_name();

113

114

/**

115

* Set the screen name this tweet is replying to.

116

* @param in_reply_to_screen_name Screen name or empty string

117

*/

118

public void setIn_reply_to_screen_name(String in_reply_to_screen_name);

119

120

/**

121

* Get the status ID this tweet is replying to.

122

* @return Status ID or 0

123

*/

124

public long getIn_reply_to_status_id();

125

126

/**

127

* Set the status ID this tweet is replying to.

128

* @param in_reply_to_status_id Status ID or 0

129

*/

130

public void setIn_reply_to_status_id(long in_reply_to_status_id);

131

132

/**

133

* Get the user ID this tweet is replying to.

134

* @return User ID or 0

135

*/

136

public long getIn_reply_to_user_id();

137

138

/**

139

* Set the user ID this tweet is replying to.

140

* @param in_reply_to_user_id User ID or 0

141

*/

142

public void setIn_reply_to_user_id(long in_reply_to_user_id);

143

144

// Engagement metrics

145

/**

146

* Get the number of times this tweet has been retweeted.

147

* @return Retweet count

148

*/

149

public long getRetweet_count();

150

151

/**

152

* Set the number of times this tweet has been retweeted.

153

* @param retweet_count Retweet count

154

*/

155

public void setRetweet_count(long retweet_count);

156

157

/**

158

* Get the number of times this tweet has been favorited.

159

* @return Favorite count

160

*/

161

public long getFavorite_count();

162

163

/**

164

* Set the number of times this tweet has been favorited.

165

* @param favorite_count Favorite count

166

*/

167

public void setFavorite_count(long favorite_count);

168

169

/**

170

* Check if this tweet has been favorited by the authenticated user.

171

* @return true if favorited

172

*/

173

public boolean isFavorited();

174

175

/**

176

* Set whether this tweet has been favorited by the authenticated user.

177

* @param favorited true if favorited

178

*/

179

public void setFavorited(boolean favorited);

180

181

/**

182

* Check if this tweet has been retweeted by the authenticated user.

183

* @return true if retweeted

184

*/

185

public boolean isRetweeted();

186

187

/**

188

* Set whether this tweet has been retweeted by the authenticated user.

189

* @param retweeted true if retweeted

190

*/

191

public void setRetweeted(boolean retweeted);

192

193

// Content classification

194

/**

195

* Get the language of the tweet content.

196

* @return ISO 639-1 language code

197

*/

198

public String getLang();

199

200

/**

201

* Set the language of the tweet content.

202

* @param lang ISO 639-1 language code

203

*/

204

public void setLang(String lang);

205

206

/**

207

* Check if the tweet may contain sensitive material.

208

* @return true if possibly sensitive

209

*/

210

public boolean getPossibly_sensitive();

211

212

/**

213

* Set whether the tweet may contain sensitive material.

214

* @param possibly_sensitive true if possibly sensitive

215

*/

216

public void setPossibly_sensitive(boolean possibly_sensitive);

217

218

/**

219

* Get the filter level applied to this tweet.

220

* @return Filter level string

221

*/

222

public String getFilter_level();

223

224

/**

225

* Set the filter level applied to this tweet.

226

* @param filter_level Filter level string

227

*/

228

public void setFilter_level(String filter_level);

229

230

// Related objects

231

/**

232

* Get the user who posted this tweet.

233

* @return Users object containing user information

234

*/

235

public Users getUser();

236

237

/**

238

* Set the user who posted this tweet.

239

* @param user Users object containing user information

240

*/

241

public void setUser(Users user);

242

243

/**

244

* Get the entities parsed from this tweet.

245

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

246

*/

247

public Entities getEntities();

248

249

/**

250

* Set the entities parsed from this tweet.

251

* @param entities Entities object containing hashtags, URLs, mentions, etc.

252

*/

253

public void setEntities(Entities entities);

254

255

/**

256

* Get the geographic coordinates of this tweet.

257

* @return Coordinates object or null

258

*/

259

public Coordinates getCoordinates();

260

261

/**

262

* Set the geographic coordinates of this tweet.

263

* @param coordinates Coordinates object or null

264

*/

265

public void setCoordinates(Coordinates coordinates);

266

267

/**

268

* Get the place information for this tweet.

269

* @return Places object or null

270

*/

271

public Places getPlace();

272

273

/**

274

* Set the place information for this tweet.

275

* @param place Places object or null

276

*/

277

public void setPlace(Places place);

278

279

/**

280

* Get the list of contributors to this tweet.

281

* @return List of Contributors objects

282

*/

283

public List<Contributors> getContributors();

284

285

/**

286

* Set the list of contributors to this tweet.

287

* @param contributors List of Contributors objects

288

*/

289

public void setContributors(List<Contributors> contributors);

290

291

/**

292

* Get the original tweet if this is a retweet.

293

* @return Tweet object of original tweet or null

294

*/

295

public Tweet getRetweeted_status();

296

297

/**

298

* Set the original tweet if this is a retweet.

299

* @param retweeted_status Tweet object of original tweet or null

300

*/

301

public void setRetweeted_status(Tweet retweeted_status);

302

303

/**

304

* Get the current user's retweet information.

305

* @return CurrentUserRetweet object or null

306

*/

307

public CurrentUserRetweet getCurrentUserRetweet();

308

309

/**

310

* Set the current user's retweet information.

311

* @param currentUserRetweet CurrentUserRetweet object or null

312

*/

313

public void setCurrentUserRetweet(CurrentUserRetweet currentUserRetweet);

314

315

/**

316

* Get the nesting level of this tweet (for retweet handling).

317

* @return Nesting level (0 for original tweets)

318

*/

319

public int getTweetLevel();

320

321

/**

322

* Set the nesting level of this tweet (for retweet handling).

323

* @param tweetLevel Nesting level (0 for original tweets)

324

*/

325

public void setTweetLevel(int tweetLevel);

326

}

327

```

328

329

**Usage Examples:**

330

331

```java

332

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

333

import org.apache.flink.contrib.tweetinputformat.model.User.Users;

334

335

// Basic tweet processing

336

Tweet tweet = new Tweet();

337

System.out.println("Tweet: " + tweet.getText());

338

System.out.println("Author: @" + tweet.getUser().getScreen_name());

339

System.out.println("Retweets: " + tweet.getRetweet_count());

340

System.out.println("Favorites: " + tweet.getFavorite_count());

341

342

// Check if tweet is a reply

343

if (tweet.getIn_reply_to_status_id() > 0) {

344

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

345

}

346

347

// Check if tweet is a retweet

348

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

349

Tweet originalTweet = tweet.getRetweeted_status();

350

System.out.println("Retweeting: @" + originalTweet.getUser().getScreen_name());

351

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

352

}

353

354

// Process entities

355

if (tweet.getEntities().getHashtags().size() > 0) {

356

System.out.println("Hashtags:");

357

for (HashTags tag : tweet.getEntities().getHashtags()) {

358

System.out.println(" #" + tag.getText());

359

}

360

}

361

362

// Geographic information

363

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

364

double[] coords = tweet.getCoordinates().getCoordinates();

365

System.out.printf("Location: %.6f, %.6f%n", coords[0], coords[1]);

366

}

367

```

368

369

### Contributors

370

371

Information about users who contributed to the authorship of a tweet.

372

373

```java { .api }

374

/**

375

* Users who contributed to the authorship of a tweet on behalf of the official author.

376

*/

377

public class Contributors {

378

379

/**

380

* Default constructor.

381

*/

382

public Contributors();

383

384

/**

385

* Constructor with contributor information.

386

* @param id Contributor user ID

387

* @param id_str Contributor user ID as string

388

* @param screenName Contributor screen name

389

*/

390

public Contributors(long id, String id_str, String screenName);

391

392

/**

393

* Reset all fields for object reuse.

394

*/

395

public void reset();

396

397

/**

398

* Get the contributor's user ID.

399

* @return User ID

400

*/

401

public long getId();

402

403

/**

404

* Set the contributor's user ID.

405

* @param id User ID

406

*/

407

public void setId(long id);

408

409

/**

410

* Get the contributor's user ID as string.

411

* @return User ID as string

412

*/

413

public String getId_str();

414

415

/**

416

* Set the contributor's user ID as string.

417

* @param id_str User ID as string

418

*/

419

public void setId_str(String id_str);

420

421

/**

422

* Get the contributor's screen name.

423

* @return Screen name

424

*/

425

public String getScreenName();

426

427

/**

428

* Set the contributor's screen name.

429

* @param screenName Screen name

430

*/

431

public void setScreenName(String screenName);

432

}

433

```

434

435

### CurrentUserRetweet

436

437

Information about the current user's retweet of this tweet.

438

439

```java { .api }

440

/**

441

* Information about the current user's retweet of this tweet.

442

* Contains the tweet ID of the user's own retweet (if it exists).

443

*/

444

public class CurrentUserRetweet {

445

446

/**

447

* Default constructor that initializes and resets all fields.

448

*/

449

public CurrentUserRetweet();

450

451

/**

452

* Reset all fields for object reuse.

453

*/

454

public void reset();

455

456

/**

457

* Get the ID of the user's retweet.

458

* @return Retweet ID

459

*/

460

public long getId();

461

462

/**

463

* Set the ID of the user's retweet.

464

* @param id Retweet ID

465

*/

466

public void setId(long id);

467

468

/**

469

* Get the string representation of the retweet ID.

470

* @return Retweet ID as string

471

*/

472

public String getId_str();

473

474

/**

475

* Set the string representation of the retweet ID (computed from numeric ID).

476

*/

477

public void setId_str();

478

}

479

```

480

481

## Serialization Notes

482

483

The Tweet class is optimized for Flink's Kryo serialization:

484

485

- **reset() method**: Clears all fields to avoid serialization issues

486

- **Level handling**: Prevents infinite recursion in nested retweets

487

- **Object reuse**: Designed for efficient memory usage in stream processing

488

- **Default values**: All fields initialized to prevent null pointer exceptions

489

490

```java

491

// Kryo optimization example

492

Tweet tweet = new Tweet();

493

tweet.reset(0); // Reset for reuse

494

495

// Process tweet...

496

497

tweet.reset(0); // Reset before reusing object

498

```