Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'master' into rhbz800869
Browse files Browse the repository at this point in the history
Conflicts:
	server/zanata-war/src/main/java/org/zanata/action/ReindexAsyncBean.java
  • Loading branch information
alex-sl-eng committed Apr 19, 2012
2 parents f4ac932 + ff8baff commit 8929248
Show file tree
Hide file tree
Showing 44 changed files with 3,418 additions and 494 deletions.
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang.StringUtils;
Expand All @@ -25,6 +24,7 @@
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.util.HashUtil;
import org.zanata.util.ShortString;
import org.zanata.util.StringUtil;

import com.google.common.collect.ImmutableSet;

Expand Down Expand Up @@ -284,46 +284,50 @@ else if (inputSource.getSystemId() != null)
return messageParser;
}

private static boolean allNonEmpty(Collection<?> coll)
private static boolean allNonEmpty(Message message)
{
if (coll == null)
return false;
for (Object o : coll)
if (message.isPlural())
{
if (o == null)
return false;
return !message.getMsgstrPlural().isEmpty() && StringUtil.allNonEmpty(message.getMsgstrPlural());
}
else
{
return message.getMsgstr() != null && !message.getMsgstr().isEmpty();
}
return true;
}

private static boolean allEmpty(List<String> strings)
private static boolean allEmpty(Message message)
{
if (strings == null)
return true;
for (String s : strings)
if (message.isPlural())
{
return StringUtil.allEmpty(message.getMsgstrPlural());
}
else
{
if (s != null && !s.isEmpty())
return false;
return message.getMsgstr() == null || message.getMsgstr().isEmpty();
}
return true;
}

static ContentState getContentState(Message message)
{
boolean fuzzy = message.isFuzzy();
if (message.isPlural() && allEmpty(message.getMsgstrPlural()))

if (allEmpty(message))
{
fuzzy = false;
}
if (fuzzy)
{
return ContentState.NeedReview;
}
if ((message.getMsgstr() != null && !message.getMsgstr().isEmpty()) || allNonEmpty(message.getMsgstrPlural()))
if (allNonEmpty(message))
{
return ContentState.Approved;
}
return ContentState.New;
else
{
return ContentState.New;
}
}

static String createId(Message message)
Expand Down
Expand Up @@ -15,10 +15,12 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.fedorahosted.tennera.jgettext.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import org.xml.sax.InputSource;
import org.zanata.common.ContentState;
import org.zanata.common.LocaleId;
import org.zanata.rest.dto.resource.Resource;
import org.zanata.rest.dto.resource.TextFlow;
Expand Down Expand Up @@ -116,4 +118,136 @@ public void extractInvalidTarget() throws IOException, JAXBException
poReader.extractTarget(inputSource, srcDoc);
}

public void testContentStateApprovedSingle()
{
Message m = new Message();
m.setMsgstr("s");
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.Approved));
}

public void testContentStateApprovedPlural1()
{
Message m = new Message();
m.setMsgidPlural("plural");
m.addMsgstrPlural("s0", 0);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.Approved));
}

public void testContentStateApprovedPlural2()
{
Message m = new Message();
m.setMsgidPlural("plural");
m.addMsgstrPlural("s0", 0);
m.addMsgstrPlural("s1", 1);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.Approved));
}

public void testContentStateNewSingle1()
{
Message m = new Message();
m.setMsgstr("");
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.New));
}

public void testContentStateNewSingle2()
{
Message m = new Message();
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.New));
}

public void testContentStateNewPlural1()
{
Message m = new Message();
m.setMsgidPlural("plural");
m.addMsgstrPlural("", 0);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.New));
}

public void testContentStateNewPlural2()
{
Message m = new Message();
m.setMsgidPlural("plural");
m.addMsgstrPlural("", 0);
m.addMsgstrPlural("s1", 1);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.New));
}

public void testContentStateNewPlural3()
{
Message m = new Message();
m.setMsgidPlural("plural");
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.New));
}

public void testContentStateNewPlural4()
{
Message m = new Message();
m.setMsgidPlural("plural");
m.addMsgstrPlural("", 0);
m.addMsgstrPlural("", 1);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.New));
}

// FIXME test where plurals < nplurals
// public void testContentStateNewPluralTooFew()
// {
// // TODO set nplurals=2
// Message m = new Message();
// m.setMsgidPlural("plural");
// m.addMsgstrPlural("s0", 0);
// ContentState actual1 = PoReader2.getContentState(m);
// assertThat(actual1, is(ContentState.New));
// }

public void testContentStateNeedReviewSingle()
{
Message m = new Message();
m.setFuzzy(true);
m.setMsgstr("s");
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.NeedReview));
}

public void testContentStateNeedReviewPlural1()
{
Message m = new Message();
m.setFuzzy(true);
m.setMsgidPlural("plural");
m.addMsgstrPlural("s", 0);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.NeedReview));
}

public void testContentStateNeedReviewPlural2()
{
Message m = new Message();
m.setFuzzy(true);
m.setMsgidPlural("plural");
m.addMsgstrPlural("", 0);
m.addMsgstrPlural("s1", 1);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.NeedReview));
}

public void testContentStateNeedReviewPlural3()
{
Message m = new Message();
m.setFuzzy(true);
m.setMsgidPlural("plural");
m.addMsgstrPlural("s0", 0);
m.addMsgstrPlural("s1", 1);
ContentState actual1 = PoReader2.getContentState(m);
assertThat(actual1, is(ContentState.NeedReview));
}

}

@@ -1,6 +1,7 @@
package org.zanata.util;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

Expand All @@ -27,4 +28,28 @@ public static List<String> split(String s, String delim)
return Arrays.asList(s.split(","));
}

public static boolean allNonEmpty(Collection<String> strings)
{
for (String s : strings)
{
if (s == null || s.isEmpty())
{
return false;
}
}
return true;
}

public static boolean allEmpty(Collection<String> strings)
{
for (String s : strings)
{
if (s != null && !s.isEmpty())
{
return false;
}
}
return true;
}

}
14 changes: 8 additions & 6 deletions server/zanata-model/pom.xml
Expand Up @@ -67,16 +67,11 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>net.sf.okapi.lib</groupId>
<artifactId>okapi-lib-search</artifactId>
<version>0.7</version>
</dependency>

<dependency>
<groupId>net.sf.okapi.steps</groupId>
<artifactId>okapi-step-wordcount</artifactId>
<version>0.9</version>
<!-- see latest version at http://repository-okapi.forge.cloudbees.com/snapshot/net/sf/okapi/steps/okapi-step-wordcount/ -->
</dependency>

<dependency>
Expand All @@ -92,6 +87,13 @@
<version>${lucene.version}</version>
</dependency>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers</artifactId>
<!-- okapi-lib-search would otherwise use lucene 3.0.0 -->
<version>${lucene.version}</version>
</dependency>

<!-- Hibernate / JPA -->
<dependency>
<groupId>org.jboss.seam</groupId>
Expand Down
@@ -0,0 +1,42 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.hibernate.search;


/**
* Analyzer that tokenizes into trigrams, preserving case.
*
* @author David Mason, damason@redhat.com
*/
public class CaseSensitiveNgramAnalyzer extends ConfigurableNgramAnalyzer
{

public CaseSensitiveNgramAnalyzer()
{
super(3, false);
}

public CaseSensitiveNgramAnalyzer(int ngramLength)
{
super(ngramLength, false);
}

}

0 comments on commit 8929248

Please sign in to comment.