Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
*.ear
*.zip
vendors/WordCram
target
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
MANIFEST.MF

8 changes: 8 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.1.19</version>
</extension>
</extensions>
1 change: 1 addition & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
33 changes: 28 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
task default: [:install_jars, :gem]
require_relative 'lib/ruby_wordcram/version'

desc 'Build gem'
def create_manifest
title = 'Implementation-Title: WordCram for JRubyArt and propane)'
version = format('Implementation-Version: %s', WordCram::VERSION)
File.open('MANIFEST.MF', 'w') do |f|
f.puts(title)
f.puts(version)
f.puts('Class-Path: jsoup-1.10.2.jar')
end
end

task default: [:init, :compile, :install]

desc 'Create Manifest'
task :init do
create_manifest
end

desc 'Install'
task :install do
sh 'mvn dependency:copy'
sh 'mv target/WordCram.jar lib'
end

desc 'Gem'
task :gem do
sh 'gem build ruby_wordcram.gemspec'
end

desc 'Install jars'
task :install_jars do
sh "cd vendors && rake"
desc 'Compile'
task :compile do
sh 'mvn package'
end
3 changes: 1 addition & 2 deletions lib/ruby_wordcram.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: false
if RUBY_PLATFORM == 'java'
require 'WordCram.jar'
require 'jsoup-1.7.2.jar'
require 'cue.language.jar'
require 'jsoup-1.10.2.jar'
wc = %w(WordAngler WordColorer WordCram WordFonter WordPlacer WordSkipReason)
sh = %w(Colorers ImageShaper Observer Placers Word ShapeBasedPlacer)
WC = wc.concat(sh).freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_wordcram/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module WordCram
VERSION = '1.0.1'.freeze
VERSION = '2.0.0'.freeze
end
53 changes: 53 additions & 0 deletions pom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
project 'Wordcram' do

model_version '4.0.0'
id 'wordcram:WordCram:2.0.0'
packaging 'jar'

properties(
'source.directory' => 'src',
'wordcram.basedir' => '${project.basedir}',
'polyglot.dump.pom' => 'pom.xml',
'maven.compiler.source' => '1.8',
'project.build.sourceEncoding' => 'utf-8',
'maven.compiler.target' => '1.8'
)

overrides do
plugin( :jar,
'archive' => {
'manifestEntries' => {
'Built-By' => 'monkstone'
}
} )
end

jar 'org.processing:core:3.3.0'
jar 'org.jsoup:jsoup:1.10.2'

build do
default_goal 'package'
source_directory 'source.directory'
final_name 'WordCram'
resource do
directory 'src'
includes
excludes '**/*.java'
end
end

overrides do
plugin :resources, '2.6'
plugin :dependency, '2.10' do
execute_goals( id: 'default-cli',
artifactItems: [ { groupId: 'org.jsoup',
artifactId: 'jsoup',
version: '1.10.2',
type: 'jar',
outputDirectory: '${wordcram.basedir}/lib'
}
]
)
end
end
end
87 changes: 87 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--


DO NOT MODIFIY - GENERATED CODE


-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>wordcram</groupId>
<artifactId>WordCram</artifactId>
<version>2.0.0</version>
<name>Wordcram</name>
<properties>
<source.directory>src</source.directory>
<wordcram.basedir>${project.basedir}</wordcram.basedir>
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.processing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>source.directory</sourceDirectory>
<defaultGoal>package</defaultGoal>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<finalName>WordCram</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Built-By>monkstone</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
<type>jar</type>
<outputDirectory>${wordcram.basedir}/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
3 changes: 1 addition & 2 deletions ruby_wordcram.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'http://ruby-processing.github.io/WordCram/'
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files << 'lib/WordCram.jar'
spec.files << 'lib/cue.language.jar'
spec.files << 'lib/jsoup-1.7.2.jar'
spec.files << 'lib/jsoup-1.10.2.jar'
spec.require_paths = ['lib']
spec.add_development_dependency 'rake', '~> 12', '>= 12.0'
end
141 changes: 141 additions & 0 deletions src/cue/lang/Counter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Copyright 2009 IBM Corp

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cue.lang;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
*
* @author Jonathan Feinberg <jdf@us.ibm.com>
* @param <T>
*
*/
public class Counter<T> {
// delegate, don't extend, to prevent unauthorized monkeying with internals
private final Map<T, Integer> items = new HashMap<T, Integer>();
private int totalItemCount = 0;

public Counter() {
this.BY_FREQ_DESC = new Comparator<Entry<T, Integer>>() {
@Override
public int compare(final Entry<T, Integer> o1,
final Entry<T, Integer> o2) {
return o2.getValue() - o1.getValue();
}
};
}

public Counter(final Iterable<T> items) {
this.BY_FREQ_DESC = new Comparator<Entry<T, Integer>>() {
@Override
public int compare(final Entry<T, Integer> o1,
final Entry<T, Integer> o2) {
return o2.getValue() - o1.getValue();
}
};
noteAll(items);
}

public final void noteAll(final Iterable<T> items) {
for (final T t : items) {
note(t, 1);
}
}

public void note(final T item) {
note(item, 1);
}

public void note(final T item, final int count) {
final Integer existingCount = items.get(item);
if (existingCount != null) {
items.put(item, existingCount + count);
} else {
items.put(item, count);
}
totalItemCount += count;
}

public void merge(final Counter<T> c) {
for (final Entry<T, Integer> e : c.items.entrySet()) {
note(e.getKey(), e.getValue());
}
}

public int getTotalItemCount() {
return totalItemCount;
}

private final Comparator<Entry<T, Integer>> BY_FREQ_DESC;

/**
* @param n
* @return A list of the min(n, size()) most frequent items
*/
public List<T> getMostFrequent(final int n) {
final List<Entry<T, Integer>> all = getAllByFrequency();
final int resultSize = Math.min(n, items.size());
final List<T> result = new ArrayList<T>(resultSize);
for (final Entry<T, Integer> e : all.subList(0, resultSize)) {
result.add(e.getKey());
}
return Collections.unmodifiableList(result);
}

public List<Entry<T, Integer>> getAllByFrequency() {
final List<Entry<T, Integer>> all = new ArrayList<Entry<T, Integer>>(
items.entrySet());
Collections.sort(all, BY_FREQ_DESC);
return Collections.unmodifiableList(all);
}

public Integer getCount(final T item) {
final Integer freq = items.get(item);
if (freq == null) {
return 0;
}
return freq;
}

public void clear() {
items.clear();
}

public Set<Entry<T, Integer>> entrySet() {
return Collections.unmodifiableSet(items.entrySet());
}

public Set<T> keySet() {
return Collections.unmodifiableSet(items.keySet());
}

public List<T> keyList() {
return getMostFrequent(items.size());
}

@Override
public String toString() {
return items.toString();
}
}
10 changes: 10 additions & 0 deletions src/cue/lang/IterableText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cue.lang;

import java.util.Iterator;

abstract class IterableText implements Iterator<String>, Iterable<String> {
@Override
public Iterator<String> iterator() {
return this;
}
}
Loading