Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build wo xml #29

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
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 @@ -48,3 +48,6 @@ lib/openccg.jar
output/
src/ccg2xml/ccg2xml.py
src/srilmbridge/*.h
*.iml
.idea/
target/
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package:
mvn package

tests:
mvn test
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ This release also includes a broad English coverage grammar from the CCGBank and
* Version 1.6 or later of the Java 2 SDK (http://java.sun.com)
* For ccg2xml and other tools, Python version 2.4 to 2.7 (http://www.python.org)

# Using Maven
*****NOTE** maven will take care dependency downloading step for you, hence steps bellow can be ignored

All of the standard maven usage rules applies, to simply make `jar` you can do `mvn package`, if you're using GNU Make, can do `make package`.
The result is `openccg.jar` which can be found on `src/target` dir.

Tests can be run via `mvn test`, or `make tests`

# Libraries

Expand Down
83 changes: 64 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>opennlp</groupId>
<artifactId>ccg</artifactId>
<version>0.10.0</version>
<packaging>pom</packaging>

<modules>
<module>src/</module>
</modules>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>acceleratedtext</groupId>
<artifactId>openccg-parent</artifactId>
<version>0.10.4</version>
<packaging>pom</packaging>

<modules>
<module>src/</module>
</modules>

<scm>
<url>https://github.com/tokenmill/openccg.git</url>
<connection>scm:git:https://github.com/tokenmill/openccg.git</connection>
<developerConnection>scm:git:https://github.com/tokenmill/openccg.git</developerConnection>
<tag>openccg-0.10.1</tag>
</scm>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
</resource>
<resource>
<directory>classes</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<additionalOptions>
<additionalOption>-Xdoclint:none</additionalOption>
<excludePackageNames>target.*</excludePackageNames>
</additionalOptions>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>clojars</id>
<url>https://repo.clojars.org/</url>
</repository>
</repositories>

<distributionManagement>
<repository>
<id>clojars</id>
<url>https://repo.clojars.org</url>
</repository>
</distributionManagement>

</project>
49 changes: 49 additions & 0 deletions src/opennlp/ccg/builders/GrammarBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package opennlp.ccg.builders;

import opennlp.ccg.grammar.Grammar;
import opennlp.ccg.grammar.RuleGroup;
import opennlp.ccg.grammar.Types;
import opennlp.ccg.lexicon.Lexicon;

public class GrammarBuilder {
public static GrammarBuilder builder(){
return new GrammarBuilder();
}

private Grammar grammar;

private GrammarBuilder(){
this.grammar = new Grammar();
}

public boolean isGlobalGrammarInit(){
return this.grammar.theGrammar != null;
}

public GrammarBuilder withTypes(Types types){
this.grammar.setTypes(types);
types.setGrammar(this.grammar);
return this;
}

public GrammarBuilder withLexicon(Lexicon lexicon){
this.grammar.setLexicon(lexicon);
lexicon.setGrammar(this.grammar);
return this;
}

public GrammarBuilder withRules(RuleGroup rules){
this.grammar.setRules(rules);
rules.setGrammar(this.grammar);
return this;
}

public Grammar build(){
// Check if we added everything
assert this.grammar.lexicon != null;
assert this.grammar.rules != null;
assert this.grammar.types != null;

return this.grammar;
}
}
42 changes: 42 additions & 0 deletions src/opennlp/ccg/builders/LexiconBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package opennlp.ccg.builders;

import opennlp.ccg.lexicon.*;
import java.util.*;

public class LexiconBuilder {
public static LexiconBuilder builder(){
return new LexiconBuilder();
}

private Lexicon lexicon;
private List<Family> familyList = new ArrayList<>();
private List<MorphItem> morphList = new ArrayList<>();
private List<MacroItem> macroList = new ArrayList<>();
private LexiconBuilder(){
this.lexicon = new Lexicon();
}

public LexiconBuilder addFamily(Family family){
this.familyList.add(family);
return this;
}

public LexiconBuilder addMorph(MorphItem item){
this.morphList.add(item);
return this;
}

public LexiconBuilder addMacro(MacroItem item){
this.macroList.add(item);
return this;
}

public Lexicon ref(){
return this.lexicon;
}

public Lexicon build(){
this.lexicon.init(familyList, morphList, macroList);
return this.lexicon;
}
}
24 changes: 24 additions & 0 deletions src/opennlp/ccg/builders/RulesBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package opennlp.ccg.builders;

import opennlp.ccg.grammar.RuleGroup;
import opennlp.ccg.grammar.Rule;

public class RulesBuilder {
public static RulesBuilder builder(){
return new RulesBuilder();
}

private RuleGroup rules;
private RulesBuilder(){
this.rules = new RuleGroup();
}

public RulesBuilder addRule(Rule rule){
this.rules.addRule(rule);
return this;
}

public RuleGroup build(){
return this.rules;
}
}
39 changes: 39 additions & 0 deletions src/opennlp/ccg/builders/TypesBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package opennlp.ccg.builders;

import opennlp.ccg.grammar.Types;
import org.jdom.Element;

import java.util.ArrayList;
import java.util.List;

public class TypesBuilder {
public static TypesBuilder builder(){
return new TypesBuilder();
}

private List<Element> elementList = new ArrayList<>();
private Types types;
private TypesBuilder(){
this.types = new Types();
}

public TypesBuilder addType(String name){
Element el = new Element("type");
el.setAttribute("name", name);
elementList.add(el);
return this;
}

public TypesBuilder addType(String name, String parents){
Element el = new Element("type");
el.setAttribute("name", name);
el.setAttribute("parents", parents);
elementList.add(el);
return this;
}

public Types build(){
this.types.readTypes(this.elementList);
return this.types;
}
}
26 changes: 22 additions & 4 deletions src/opennlp/ccg/grammar/Grammar.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
public class Grammar {

/** The lexicon. */
public final Lexicon lexicon;
public Lexicon lexicon;

/** The rule group. */
public final RuleGroup rules;
public RuleGroup rules;

/** The type hierarchy. */
public final Types types;
public Types types;

/** The features to include in supertags. */
public final Set<String> supertagFeatures = new HashSet<String>();
Expand Down Expand Up @@ -109,7 +109,25 @@ public class Grammar {
};

// set of boundary tones
private static Set<String> boundaryTonesSet = null;
private static Set<String> boundaryTonesSet = null;

public Grammar(){
theGrammar = this;
this.fromXmlTransforms = new URL[0];
this.toXmlTransforms = new URL[0];
}

public void setTypes(Types types){
this.types = types;
}

public void setLexicon(Lexicon lexicon){
this.lexicon = lexicon;
}

public void setRules(RuleGroup rules){
this.rules = rules;
}


/** Loads a grammar from the given filename. */
Expand Down
11 changes: 10 additions & 1 deletion src/opennlp/ccg/grammar/RuleGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @author Michael White
* @version $Revision: 1.32 $, $Date: 2011/06/07 05:12:01 $
*/
public class RuleGroup implements Serializable {
public class RuleGroup implements Serializable, WithGrammar {

private static final long serialVersionUID = -6240266013357142289L;

Expand Down Expand Up @@ -156,6 +156,11 @@ SupercatRuleCombo get(SupercatRuleCombo combo) {
/**
* Constructs an empty rule group for the given grammar.
*/

public RuleGroup(){
bapp.setRuleGroup(this);
}

public RuleGroup(Grammar grammar) {
this.grammar = grammar;
bapp.setRuleGroup(this);
Expand Down Expand Up @@ -185,6 +190,10 @@ public void handleElement(Element ruleEl) {
ruleScanner.parse(url);
}

public void setGrammar(Grammar grammar){
this.grammar = grammar;
}


// during deserialization, sets grammar to the current grammar
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
Expand Down
Loading