markov 1.0.3 copy "markov: ^1.0.3" to clipboard
markov: ^1.0.3 copied to clipboard

outdatedDart 1 only

A simple Markov chain implementation. Generates words and punctuation. Tuned for tweets.

example/example.dart

// Copyright (c) 2016, <your name>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

library markov.example;

import 'dart:convert';
import 'dart:io';

import 'package:markov/markov.dart';

main() async {
  print("Provide source text by stdin. For best result, provide a large number "
      "of tweets, one per line.\n\n"
      "  \$ dart example.dart < tweets.txt\n"
      "  Here's your generated tweet.");

  // Take POSIX standard input stream (or any other byte
  // stream) and use it as source text.
  var chain = await stdin
      .transform(new Utf8Decoder())
      .transform(new LineSplitter())
      .pipe(new MarkovChainGenerator(2));

  // Take just one tweet worth of generated content (terminated by a newline).
  List<Token> tokens =
      chain.generate().takeWhile((token) => token.string != "\n").toList();

  print(format(tokens));
}
3
likes
40
pub points
22%
popularity

Publisher

unverified uploader

A simple Markov chain implementation. Generates words and punctuation. Tuned for tweets.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

quiver, string_scanner

More

Packages that depend on markov