Code Search for Developers
 
 
  

ValidateGrammarEntities.java from Texai at Krugle


Show ValidateGrammarEntities.java syntax highlighted

/*
 * ValidateGrammarEntities.java
 *
 * Created on August 29, 2007, 12:26 PM
 *
 * Description: Validates the grammar repository contents.
 *
 * Copyright (C) August 29, 2007 Stephen L. Reed.
 *
 * This program is free software; you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package org.texai.grammar.domainEntity;

import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.NotThreadSafe;
import net.sf.ehcache.CacheManager;
import org.apache.log4j.Logger;
import org.openrdf.OpenRDFException;
import org.openrdf.model.URI;
import org.openrdf.query.MalformedQueryException;
import org.openrdf.query.QueryLanguage;
import org.openrdf.query.TupleQuery;
import org.openrdf.query.TupleQueryResult;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.nativerdf.NativeStore;
import org.texai.cmudict.domainEntity.ARPABETPhoneme;
import org.texai.kb.CacheInitializer;
import org.texai.kb.Constants;
import org.texai.kb.persistence.RDFEntityManager;
import org.texai.util.TexaiException;

/** Validates the grammar repository contents.
 *
 * @author reed
 */
@NotThreadSafe
public class ValidateGrammarEntities {
  
  /** the number of validation threads */
  private static final int NBR_THREADS = 2;
  
  /** the logger */
  private final Logger LOGGER = Logger.getLogger(ValidateGrammarEntities.class);
  
  /** the Sesame repository */
  private Repository repository;
  
  /** the executor */
  private final ExecutorService executor;
  
  /** the list of URIs to validate */
  private final Set<URI> urisToValidate = new HashSet<URI>();
  
  /** the iterator of URIs to validate */
  @GuardedBy("itself")
  private Iterator<URI> urisToValidate_iter;
  
  /** the number of validated entities so far */
  @GuardedBy("nbrURIsValidated_lock")
  private volatile int nbrURIsValidated = 0;
  
  /** the lock for the number of validated entities so far */
  private Object nbrURIsValidated_lock = new Object();
  
  /** the class URIs for entities to validate */
  private String[] classURIStrings = {
    "http://texai.org/texai/org.texai.grammar.domainEntity.AlternativeConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.CategoryConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.ConstituentAdapter",
    "http://texai.org/texai/org.texai.grammar.domainEntity.OptionalConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.RegularExpression",
    "http://texai.org/texai/org.texai.grammar.domainEntity.RegularExpression_GroupVariableInfo",
    "http://texai.org/texai/org.texai.grammar.domainEntity.RepetitiveConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.SequenceConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.SimpleConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.WordFormConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.WordSenseConstruction",
    "http://texai.org/texai/org.texai.grammar.domainEntity.XMLTagWord"
  };
  
  
  
  /**
   * Creates a new instance of ValidateGrammarEntities.
   */
  public ValidateGrammarEntities() {
    executor = Executors.newFixedThreadPool(NBR_THREADS);
  }
  
  /** Initializes this application. */
  public void initialize() {
    CacheInitializer.initializeCaches();
    getClass().getClassLoader().setDefaultAssertionStatus(true);   // optional
    CacheInitializer.initializeCaches();
//    final File dataDirectory = new File(System.getProperties().getProperty("user.home") + "/.aduna/openrdf-sesame/repositories/EnglishConstructionGrammarDomain");
    final File dataDirectory = new File("/mnt/tmpfs/repositories/EnglishConstructionGrammarDomain");
    LOGGER.info("accessing the Sesame2 repository in " + dataDirectory.toString());
    final String indices = "spoc,posc";
    repository = new SailRepository(new NativeStore(dataDirectory, indices));
    try {
      repository.initialize();
    } catch (final RepositoryException ex) {
      throw new TexaiException(ex);
    }
  }

  /** Validates the CMU dictionary RDF entities. */
  public void validate() {
    for (final String classURIString : classURIStrings) {
      validateRDFEntities(classURIString);
    }
  }

  /** Validates the RDF entities having the given class URI.
   *
   * @param classURI the class URI
   */
  private void validateRDFEntities(final String classURIString) {
    LOGGER.info("");
    LOGGER.info("querying the entity URIs having class URI " + classURIString);
    try {
      final RepositoryConnection repositoryConnection = repository.getConnection();
      final String queryString =
              "SELECT s FROM {s} rdf:type {<" + classURIString + ">}";
      LOGGER.info("query: " + queryString);
      final TupleQuery tupleQuery = repositoryConnection.prepareTupleQuery(QueryLanguage.SERQL, queryString);
      final TupleQueryResult tupleQueryResult = tupleQuery.evaluate();
      urisToValidate.clear();
      while (tupleQueryResult.hasNext()) {
        urisToValidate.add((URI) tupleQueryResult.next().getBinding("s").getValue());
      }
      tupleQueryResult.close();
      if (LOGGER.isDebugEnabled()) {
        LOGGER.info("closing the query repository connection");
      }
      repositoryConnection.close();
      if (urisToValidate.isEmpty()) {
        LOGGER.info("*** no entity URIs selected " + classURIString);
        return;
      }
    } catch (final MalformedQueryException ex) {
      throw new TexaiException(ex);
    } catch (final RepositoryException ex) {
      throw new TexaiException(ex);
    } catch (final OpenRDFException ex) {
      throw new TexaiException(ex);
    }
    nbrURIsValidated = 0;
    final int urisToValidate_size = urisToValidate.size();
    LOGGER.info("found " + urisToValidate_size + " entity URIs");
    urisToValidate_iter = urisToValidate.iterator();
    final long startMillis = System.currentTimeMillis();
    final CountDownLatch doneSignal = new CountDownLatch(NBR_THREADS);
    for (int i = 0; i < NBR_THREADS; i++) {
      executor.execute(new EntityValidationRunnable(classURIString, doneSignal, i + 1));
    }
    try {
      doneSignal.await();
    } catch (InterruptedException ex) {
      throw new TexaiException(ex);
    }
    double secondsDuration = (float) ((System.currentTimeMillis() - startMillis)) / 1000.0d;
    if (secondsDuration == 0) {
      secondsDuration = 1;
    }
    LOGGER.info("validated " + urisToValidate_size + " at the rate of " + urisToValidate_size /  secondsDuration + " per second");
  }
  
  /** A parallel runnable that validates entity URIs which it obtains from the shared iterator. */
  @Immutable
  class EntityValidationRunnable implements Runnable {
    
    /** the entity class URI string */
    private final String classURIString;
    
    /** the count down latch that synchronizes the calling thread */
    private final CountDownLatch doneSignal;
    
    /** the thread id */
    private final int id;
    
    /** Constructs a new EntityValidationRunnable instance.
     *
     * @param classURIString the entity class URI string
     * @param doneSignal the count down latch that synchronizes the calling thread
     * @param id the identification for this runnable
     */
    public EntityValidationRunnable(final String classURIString, final CountDownLatch doneSignal, final int id) {
      //Preconditions
      assert doneSignal != null : "doneSignal must not be null";
      assert classURIString != null : "classURIString must not be null";
      assert !classURIString.isEmpty() : "classURIString must not be empty";
      
      this.classURIString = classURIString;
      this.doneSignal = doneSignal;
      this.id = id;
    }
    
    /** Executes this thread. */
    public void run() {
      RDFEntityManager rdfEntityManager = null;
      try {
        LOGGER.info("starting " + id);
        Thread.currentThread().setName("validator " + id);
        rdfEntityManager = new RDFEntityManager(repository);
        int nbrURIsProcessed = 0;
        boolean isDone = false;
        while (! isDone) {
          final URI uri = getNextEntityURIToValidate();
          if (uri == null) {
            isDone = true;
          } else {
            boolean isLogged = false;
            synchronized (nbrURIsValidated_lock) {
              nbrURIsValidated++;
              if (nbrURIsValidated % 2500 == 0) {
                isLogged = true;
                CacheInitializer.resetCache(Constants.CACHE_CONNECTED_RDF_ENTITIES);
              }
            }
            if ("http://texai.org/texai/org.texai.grammar.domainEntity.AlternativeConstruction".equals(classURIString)) {
              validateAlternativeConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.CategoryConstruction".equals(classURIString)) {
              validateCategoryConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.ConstituentAdapter".equals(classURIString)) {
              validateConstituentAdapter(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.OptionalConstruction".equals(classURIString)) {
              validateOptionalConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.RegularExpression".equals(classURIString)) {
              validateRegularExpression(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.RegularExpression_GroupVariableInfo".equals(classURIString)) {
              validateRegularExpression_GroupVariableInfo(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.RepetitiveConstruction".equals(classURIString)) {
              validateRepetitiveConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.SequenceConstruction".equals(classURIString)) {
              validateSequenceConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.SimpleConstruction".equals(classURIString)) {
              validateSimpleConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.WordFormConstruction".equals(classURIString)) {
              validateWordFormConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.WordSenseConstruction".equals(classURIString)) {
              validateWordSenseConstruction(rdfEntityManager, uri, isLogged);
            } else if ("http://texai.org/texai/org.texai.grammar.domainEntity.XMLTagWord".equals(classURIString)) {
              validateXMLTagWord(rdfEntityManager, uri, isLogged);
            }
            nbrURIsProcessed++;
          }
        }
        LOGGER.info("thread " + id + " completed " + nbrURIsProcessed + " entity URIs");
        doneSignal.countDown();
      } catch (final Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
        ex.printStackTrace();
      } finally {
        if (rdfEntityManager != null) {
          rdfEntityManager.close();
        }
      }
    }
  }
  
  /** Validates the AlternativeConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateAlternativeConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final AlternativeConstruction alternativeConstruction = (AlternativeConstruction) rdfEntityManager.find(AlternativeConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(alternativeConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!alternativeConstruction.getId().equals(uri)) {
      LOGGER.warn(alternativeConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + alternativeConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the CategoryConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateCategoryConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final CategoryConstruction categoryConstruction = (CategoryConstruction) rdfEntityManager.find(CategoryConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(categoryConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!categoryConstruction.getId().equals(uri)) {
      LOGGER.warn(categoryConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + categoryConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the ConstituentAdapter entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateConstituentAdapter(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final ConstituentAdapter constituentAdapter = (ConstituentAdapter) rdfEntityManager.find(ConstituentAdapter.class, uri);
    if (isLogged) {
      LOGGER.info(constituentAdapter.toString() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!constituentAdapter.getId().equals(uri)) {
      LOGGER.warn(constituentAdapter + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + constituentAdapter.getId());
    }
    
    //TODO
  }
  
  /** Validates the OptionalConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateOptionalConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final OptionalConstruction optionalConstruction = (OptionalConstruction) rdfEntityManager.find(OptionalConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(optionalConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!optionalConstruction.getId().equals(uri)) {
      LOGGER.warn(optionalConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + optionalConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the ARPABETPhoneme entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateARPABETPhoneme(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final ARPABETPhoneme arpabetPhoneme = (ARPABETPhoneme) rdfEntityManager.find(ARPABETPhoneme.class, uri);
    if (isLogged) {
      LOGGER.info(arpabetPhoneme.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!arpabetPhoneme.getId().equals(uri)) {
      LOGGER.warn(arpabetPhoneme + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + arpabetPhoneme.getId());
    }
    
    //TODO
  }
  
  /** Validates the RegularExpression entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateRegularExpression(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final RegularExpression regularExpression = (RegularExpression) rdfEntityManager.find(RegularExpression.class, uri);
    if (isLogged) {
      LOGGER.info(regularExpression.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!regularExpression.getId().equals(uri)) {
      LOGGER.warn(regularExpression + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + regularExpression.getId());
    }
    
    //TODO
  }
  
  /** Validates the RegularExpression_GroupVariableInfo entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateRegularExpression_GroupVariableInfo(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final RegularExpression_GroupVariableInfo RegularExpression_GroupVariableInfo = 
            (RegularExpression_GroupVariableInfo) rdfEntityManager.find(RegularExpression_GroupVariableInfo.class, uri);
    if (isLogged) {
      LOGGER.info(RegularExpression_GroupVariableInfo.toString() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!RegularExpression_GroupVariableInfo.getId().equals(uri)) {
      LOGGER.warn(RegularExpression_GroupVariableInfo + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + RegularExpression_GroupVariableInfo.getId());
    }
    
    //TODO
  }
  
  /** Validates the RepetitiveConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateRepetitiveConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final RepetitiveConstruction repetitiveConstruction = (RepetitiveConstruction) rdfEntityManager.find(RepetitiveConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(repetitiveConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!repetitiveConstruction.getId().equals(uri)) {
      LOGGER.warn(repetitiveConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + repetitiveConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the SequenceConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateSequenceConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final SequenceConstruction sequenceConstruction = (SequenceConstruction) rdfEntityManager.find(SequenceConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(sequenceConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!sequenceConstruction.getId().equals(uri)) {
      LOGGER.warn(sequenceConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + sequenceConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the SimpleConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateSimpleConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final SimpleConstruction simpleConstruction = (SimpleConstruction) rdfEntityManager.find(SimpleConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(simpleConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!simpleConstruction.getId().equals(uri)) {
      LOGGER.warn(simpleConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + simpleConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the WordFormConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateWordFormConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final WordFormConstruction wordFormConstruction = (WordFormConstruction) rdfEntityManager.find(WordFormConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(wordFormConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!wordFormConstruction.getId().equals(uri)) {
      LOGGER.warn(wordFormConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + wordFormConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the WordSenseConstruction entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateWordSenseConstruction(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final WordSenseConstruction wordSenseConstruction = (WordSenseConstruction) rdfEntityManager.find(WordSenseConstruction.class, uri);
    if (isLogged) {
      LOGGER.info(wordSenseConstruction.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!wordSenseConstruction.getId().equals(uri)) {
      LOGGER.warn(wordSenseConstruction + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + wordSenseConstruction.getId());
    }
    
    //TODO
  }
  
  /** Validates the XMLTagWord entity.
   *
   * @param rdfEntityManager the RDF entity manager
   * @param uri the RDF entity URI
   * @param isLogged the indicator whether to log this entity
   */
  private void validateXMLTagWord(final RDFEntityManager rdfEntityManager, final URI uri, final boolean isLogged) {
    //Preconditions
    assert rdfEntityManager != null : "rdfEntityManger must not be null";
    assert uri != null : "uri must not be null";
    
    final XMLTagWord xmlTagWord = (XMLTagWord) rdfEntityManager.find(XMLTagWord.class, uri);
    if (isLogged) {
      LOGGER.info(xmlTagWord.getName() + " by thread " + Thread.currentThread().getName());
    }
    
    // the id
    if (!xmlTagWord.getId().equals(uri)) {
      LOGGER.warn(xmlTagWord + " ids are not equal");
    } else if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("id OK for " + xmlTagWord.getId());
    }
    
    //TODO
  }
  
  /** Gets the next entity URI to validate.
   *
   * @return the next WordNet synset URI to validate, or null when done
   */
  private URI getNextEntityURIToValidate() {
    synchronized(urisToValidate_iter) {
      if (urisToValidate_iter.hasNext()) {
        return  urisToValidate_iter.next();
      } else {
        return null;
      }
    }
  }
  

  /** Finalizes this application. */
  public void finalization() {
    executor.shutdown();
    CacheManager.getInstance().shutdown();
    try {
      repository.shutDown();
    } catch (final RepositoryException ex) {
      throw new TexaiException(ex);
    }
    LOGGER.info("ValidateGrammarEntities completed");
  }

  /** Executes this application.
   *
   * @param args the command line arguments (unused)
   */
  public static void main(final String[] args) {
    final ValidateGrammarEntities validateCMUPronouncingDictionaryEntities = new ValidateGrammarEntities();
    validateCMUPronouncingDictionaryEntities.initialize();
    validateCMUPronouncingDictionaryEntities.validate();
    validateCMUPronouncingDictionaryEntities.finalization();
    System.exit(0);
  }
}




See more files for this project here

Texai

Texai is an chatbot that intelligently seeks to acquire knowledge and friendly behaviors.

Project homepage: http://sourceforge.net/projects/texai
Programming language(s): Java,Shell Script,XML
License: other

  AbstractComposedConstruction.java
  AbstractConstruction.java
  AlternativeConstruction.java
  CategoryConstruction.java
  ConstituentAdapter.java
  OptionalConstruction.java
  RegularExpression.java
  RegularExpression_GroupVariableInfo.java
  RepetitiveConstruction.java
  SequenceConstruction.java
  SimpleConstruction.java
  ValidateGrammarEntities.java
  WordFormConstruction.java
  WordSenseConstruction.java
  XMLTagWord.java