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
4 changes: 4 additions & 0 deletions src/main/java/org/culturegraph/mf/morph/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public void setName(final String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}
15 changes: 8 additions & 7 deletions src/main/java/org/culturegraph/mf/util/tries/WildcardTrie.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
Expand All @@ -26,6 +28,7 @@
* A simple Trie, which accepts a trailing wildcard
*
* @author Markus Michael Geipel
* @author Pascal Christoph
*
* @param <P>
* type of value stored
Expand Down Expand Up @@ -77,7 +80,6 @@ private void simplyPut(final String key, final P value) {

public List<P> get(final String key) {


nodes.add(root);
final int length = key.length();
for (int i = 0; i < length; ++i) {
Expand Down Expand Up @@ -111,7 +113,7 @@ public List<P> get(final String key) {

List<P> matches = Collections.emptyList();
for (Node<P> node : nodes) {
final List<P> values = node.getValues();
final Set<P> values = node.getValues();
if (!values.isEmpty()) {
if (matches == Collections.emptyList()) {
matches = new ArrayList<P>();
Expand All @@ -130,7 +132,7 @@ public List<P> get(final String key) {
*/
private final class Node<T> {

private List<T> values = Collections.emptyList();
private Set<T> values = Collections.emptySet();
private final CharMap<Node<T>> links = new CharMap<Node<T>>();

protected Node() {
Expand All @@ -143,18 +145,17 @@ public Node<T> addNext(final char key) {
if (key == STAR_WILDCARD) {
next.links.put(STAR_WILDCARD, next);
}

return next;
}

public void addValue(final T value) {
if (values == Collections.emptyList()) {
values = new ArrayList<T>();
if (values == Collections.emptySet()) {
values = new LinkedHashSet<T>();
}
this.values.add(value);
}

public List<T> getValues() {
public Set<T> getValues() {
return values;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2013 Pascal Christoph, hbz
* 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 org.culturegraph.mf.util.tries;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
* tests {@link SimpleRegexTrie}
*
* @author Pascal Christoph
*
*/
public final class SimpleRegexTrieTest {
private static final String SCC = "aacbb|a[ab]bb";
private static final String AACBB = "aacbb";

@Test
public void testWithSimpleCharacterClass() {
final SimpleRegexTrie<String> trie = new SimpleRegexTrie<String>();
trie.put(SCC, SCC);
assertTrue(AACBB, trie.get(AACBB).size() == 1);
}
}