Changeset 2261256d076e9c65629ee11392c649b90bb74a18
- Timestamp:
- 06/12/2008 11:12:18 AM
(2 months ago)
- Author:
- mitchell <mitchell@frost.(none)>
- git-committer:
- mitchell <mitchell@frost.(none)> 1213294338 -0400
- git-parent:
[069dddc59c195676361a8943bc9c92c2cb26c09a]
- git-author:
- mitchell <mitchell@frost.(none)> 1213294338 -0400
- Message:
Ohcount -e flag does a bit better than dumping entities to screen.
It now counts entity occurances for each language and puts them in a hash for
printing.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r069dddc |
r2261256 |
|
| 72 | 72 | |
|---|
| 73 | 73 | # Entities |
|---|
| 74 | | # TODO: do more fun stuff rather than print entities and positions |
|---|
| 75 | 74 | def entities |
|---|
| | 75 | langs = Hash.new |
|---|
| 76 | 76 | files.each do |file| |
|---|
| 77 | 77 | sfc = Ohcount::SimpleFileContext.new(file, files) |
|---|
| … | … | |
| 79 | 79 | if polyglot |
|---|
| 80 | 80 | Ohcount::parse_entities(sfc.contents, polyglot) do |language, entity, s, e| |
|---|
| 81 | | puts "#{language}\t#{entity}\t#{s}\t#{e}" |
|---|
| 82 | | end |
|---|
| 83 | | end |
|---|
| 84 | | end |
|---|
| | 81 | unless langs.include? language |
|---|
| | 82 | langs[language] = Hash.new |
|---|
| | 83 | langs[language].default = 0 |
|---|
| | 84 | end |
|---|
| | 85 | langs[language][entity] += 1 |
|---|
| | 86 | end |
|---|
| | 87 | end |
|---|
| | 88 | end |
|---|
| | 89 | p langs # TODO: pretty print |
|---|
| 85 | 90 | end |
|---|
| 86 | 91 | |
|---|
| … | … | |
| 114 | 119 | -e, --entities |
|---|
| 115 | 120 | |
|---|
| 116 | | For now, simply prints the positions of entities parsed in all |
|---|
| 117 | | source files found within the given paths. |
|---|
| | 121 | Prints the number of entities found for each language parsed. |
|---|
| 118 | 122 | |
|---|
| 119 | 123 | -h, --help Display this message |
|---|
| … | … | |
| 267 | 271 | when '-e', '--entities' |
|---|
| 268 | 272 | self.subcommand = :entities |
|---|
| | 273 | #when /-n([\w_]+)/ |
|---|
| | 274 | # @entities ||= [] |
|---|
| | 275 | # @entities << $1.to_sym |
|---|
| | 276 | # self.subcommand = :entities unless @subcommand |
|---|
| 269 | 277 | when '-?', '-h', '--help' |
|---|
| 270 | 278 | self.subcommand = :help |
|---|