Coverage Report - org.kuali.student.core.statement.naturallanguage.translators.NaturalLanguageTranslatorImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NaturalLanguageTranslatorImpl
0%
0/29
0%
0/12
1.857
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.statement.naturallanguage.translators;
 17  
 
 18  
 import org.apache.log4j.Logger;
 19  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 20  
 import org.kuali.student.common.exceptions.OperationFailedException;
 21  
 import org.kuali.student.core.statement.entity.ReqComponent;
 22  
 import org.kuali.student.core.statement.entity.Statement;
 23  
 import org.kuali.student.core.statement.naturallanguage.NaturalLanguageTranslator;
 24  
 
 25  
 /**
 26  
  * This class translates requirement components and LU (learning unit) 
 27  
  * statements into a specific natural language and into a 
 28  
  * statement/requirement component tree.
 29  
  */
 30  
 public class NaturalLanguageTranslatorImpl implements NaturalLanguageTranslator {
 31  
 
 32  0
         private final static Logger logger = Logger.getLogger(NaturalLanguageTranslatorImpl.class);
 33  
         
 34  
         private ReqComponentTranslator reqComponentTranslator;
 35  
         private StatementTranslator statementTranslator;
 36  
         
 37  
         /**
 38  
          * Constructs a new natural language translator in the 
 39  
          * default language locale.
 40  
          */
 41  0
         public NaturalLanguageTranslatorImpl() {
 42  0
         }
 43  
 
 44  
         /**
 45  
          * Sets the requirement component translator.
 46  
          * 
 47  
          * @param reqComponentTranslator Requirement component translator
 48  
          */
 49  
         public void setReqComponentTranslator(final ReqComponentTranslator reqComponentTranslator) {
 50  0
                 this.reqComponentTranslator = reqComponentTranslator;
 51  0
         }
 52  
 
 53  
         /**
 54  
          * Sets the statement translator.
 55  
          * 
 56  
          * @param statementTranslator Statement translator
 57  
          */
 58  
         public void setStatementTranslator(final StatementTranslator statementTranslator) {
 59  0
                 this.statementTranslator = statementTranslator;
 60  0
         }
 61  
         
 62  
         /**
 63  
          * Translates a requirement component in the default language locale for a 
 64  
          * specific natural language, usuage type (context) into natural language.
 65  
          * 
 66  
          * @param reqComponent Requirement component to be translated
 67  
          * @param nlUsageTypeKey Natural language usage type key (context)
 68  
          * @return Natural language requirement translation
 69  
          * @throws DoesNotExistException Requirement component id does not exists
 70  
          * @throws OperationFailedException
 71  
          */
 72  
         public synchronized String translateReqComponent(final ReqComponent reqComponent, final String nlUsageTypeKey) throws DoesNotExistException, OperationFailedException {
 73  0
                 String nl = this.reqComponentTranslator.translate(reqComponent, nlUsageTypeKey);
 74  0
                 if(logger.isInfoEnabled()) {
 75  0
                         logger.info("ReqComponent translation="+nl);
 76  
                 }
 77  0
                 return nl;
 78  
         }
 79  
 
 80  
         /**
 81  
          * Translates a requirement component for a specific natural language, 
 82  
          * usuage type (context) and language locale (e.g. 'en' for English, 
 83  
          * 'de' for German) into natural language.
 84  
          * 
 85  
          * @param reqComponent Requirement component to be translated
 86  
          * @param nlUsageTypeKey Natural language usage type key (context)
 87  
          * @param language Translation language
 88  
          * @return
 89  
          * @throws DoesNotExistException
 90  
          * @throws OperationFailedException
 91  
          */
 92  
         public synchronized String translateReqComponent(final ReqComponent reqComponent, final String nlUsageTypeKey, final String language) throws DoesNotExistException, OperationFailedException {
 93  0
                 String nl = null;
 94  0
                 if(language == null) {
 95  0
                         nl = this.reqComponentTranslator.translate(reqComponent, nlUsageTypeKey);
 96  
                 } else {
 97  0
                         nl = this.reqComponentTranslator.translate(reqComponent, nlUsageTypeKey, language);
 98  
                 }
 99  0
                 if(logger.isInfoEnabled()) {
 100  0
                         logger.info("ReqComponent translation="+nl);
 101  
                 }
 102  0
                 return nl;
 103  
         }
 104  
         
 105  
         /**
 106  
          * Translates a statement for a specific natural language, 
 107  
          * usuage type (context) into natural language.
 108  
          * 
 109  
          * @param statement Statement to be translated 
 110  
          * @param nlUsageTypeKey Natural language usage type key (context)
 111  
          * @return Natural language statement translation
 112  
          * @throws DoesNotExistException CLU does not exists
 113  
          * @throws OperationFailedException Translation fails
 114  
          */
 115  
         public synchronized String translateStatement(final Statement statement, final String nlUsageTypeKey) throws DoesNotExistException, OperationFailedException {
 116  0
                 String nl = this.statementTranslator.translate(statement, nlUsageTypeKey);
 117  0
                 if(logger.isInfoEnabled()) {
 118  0
                         logger.info("Statement translation="+nl);
 119  
                 }
 120  0
                 return nl;
 121  
         }
 122  
 
 123  
         /**
 124  
          * Translates a statement for a specific natural language, 
 125  
          * usuage type (context) and language locale into natural language.
 126  
          * 
 127  
          * @param statement Statement to be translated 
 128  
          * @param nlUsageTypeKey Natural language usage type key (context)
 129  
          * @param language Translation language
 130  
          * @return Natural language statement translation
 131  
          * @throws DoesNotExistException CLU id does not exists
 132  
          * @throws OperationFailedException Translation fails
 133  
          */
 134  
         public synchronized String translateStatement(Statement statement, String nlUsageTypeKey, String language) throws DoesNotExistException, OperationFailedException {
 135  0
                 String nl = null;
 136  0
                 if(language == null) {
 137  0
                         nl = this.statementTranslator.translate(statement, nlUsageTypeKey);
 138  
                 } else {
 139  0
                         nl = this.statementTranslator.translate(statement, nlUsageTypeKey, language);
 140  
                 }
 141  0
                 if(logger.isInfoEnabled()) {
 142  0
                         logger.info("Statement translation="+nl);
 143  
                 }
 144  0
                 return nl;
 145  
         }
 146  
 }