Package org.apache.ctakes.dictionary.lookup

Examples of org.apache.ctakes.dictionary.lookup.Dictionary


      }

      final Element lookupFieldEl = rootDictEl.getChild( "lookupField" );
      final String lookupFieldName = lookupFieldEl.getAttributeValue( "fieldName" );

      Dictionary dict;
      try {
         if (rootDictEl.getChild( "implementation" ).getChildren().isEmpty() ) {
            throw new ResourceAccessException( new IndexOutOfBoundsException() );
         }
         final Element implEl = (Element) rootDictEl.getChild( "implementation" ).getChildren().get( 0 );
         final String implType = implEl.getName();
         if ( implType.equals( "luceneImpl" ) ) {
            if ( !(extResrc instanceof LuceneIndexReaderResource) ) {
               throw new ResourceAccessException( "Expected external resource to be:"
                                          + LuceneIndexReaderResource.class, new Object[]{extResrc} );
            }
            final IndexReader indexReader = ((LuceneIndexReaderResource) extResrc).getIndexReader();
            final IndexSearcher indexSearcher = new IndexSearcher( indexReader );
            // Added 'MaxListSize' ohnlp-Bugs-3296301
            dict = new LuceneDictionaryImpl( indexSearcher, lookupFieldName, MAX_LIST_SIZE );
         } else if ( implType.equals( "jdbcImpl" ) ) {
            final String tableName = implEl.getAttributeValue( "tableName" );
            if ( !(extResrc instanceof JdbcConnectionResource) ) {
               throw new ResourceAccessException( "Expected external resource to be:"
                                          + JdbcConnectionResource.class, new Object[]{extResrc} );
            }
            final Connection conn = ((JdbcConnectionResource) extResrc).getConnection();
            dict = new JdbcDictionaryImpl( conn, tableName, lookupFieldName );
         } else if ( implType.equals( "csvImpl" ) ) {
            final String fieldDelimiter = implEl.getAttributeValue( "delimiter" );
            if ( !(extResrc instanceof FileResource) ) {
               throw new ResourceAccessException( "Expected external resource to be:"
                                          + FileResource.class, new Object[]{extResrc} );
            }

            final String idxFieldNameStr = implEl.getAttributeValue( "indexedFieldNames" );
            final StringTokenizer st = new StringTokenizer( idxFieldNameStr, "," );
            int arrIdx = 0;
            String[] idxFieldNameArr = new String[st.countTokens()];
            while ( st.hasMoreTokens() ) {
               idxFieldNameArr[arrIdx++] = st.nextToken().trim();
            }

            final File csvFile = ((FileResource) extResrc).getFile();
            try {
               final StringTable strTable = StringTableFactory.build( new FileReader( csvFile ),
                     fieldDelimiter, idxFieldNameArr, true );
               dict = new StringTableDictionaryImpl( strTable, lookupFieldName );
            } catch ( FileNotFoundException fnfE ) {
               throw new ResourceAccessException( "Could not open csv file", new Object[]{csvFile} );
            } catch (IOException ioE ) {
               throw new ResourceAccessException( "Could not open csv file", new Object[]{csvFile} );
            }
         } else {
            throw new ResourceAccessException( "Unsupported impl type:" + implType, new Object[]{implType} );
         }

         final List<Element> rootDictChildren = rootDictEl.getChild( "metaFields" ).getChildren();
         for ( Element metaFieldEl : rootDictChildren ) {
            final String metaFieldName = metaFieldEl.getAttributeValue( "fieldName" );
            dict.retainMetaData( metaFieldName );
         }
      } catch ( NullPointerException npE ) {
         // thrown all over this method ...
         throw new ResourceAccessException( npE );
      }
View Full Code Here


    }

    Element lookupFieldEl = rootDictEl.getChild("lookupField");
    String lookupFieldName = lookupFieldEl.getAttributeValue("fieldName");

    Dictionary dict;

    Element implEl = (Element) rootDictEl.getChild("implementation")
        .getChildren()
        .get(0);
    String implType = implEl.getName();
    if (implType.equals("luceneImpl"))
    {
      if (!(extResrc instanceof LuceneIndexReaderResource))
      {
        throw new Exception("Expected external resource to be:"
            + LuceneIndexReaderResource.class);
      }
      IndexReader indexReader = ((LuceneIndexReaderResource) extResrc).getIndexReader();
      IndexSearcher indexSearcher = new IndexSearcher(indexReader);
      // Added 'MaxListSize' ohnlp-Bugs-3296301
      dict = new LuceneDictionaryImpl(indexSearcher, lookupFieldName, maxSizeList);
    }
    else if (implType.equals("jdbcImpl"))
    {
      String tableName = implEl.getAttributeValue("tableName");
      if (!(extResrc instanceof JdbcConnectionResource))
      {
        throw new Exception("Expected external resource to be:"
            + JdbcConnectionResource.class);
      }
      Connection conn = ((JdbcConnectionResource) extResrc).getConnection();
      dict = new JdbcDictionaryImpl(conn, tableName, lookupFieldName);
    }
        else if (implType.equals("csvImpl"))
        {
            String fieldDelimiter = implEl.getAttributeValue("delimiter");           
            if (!(extResrc instanceof FileResource))
            {
                throw new Exception("Expected external resource to be:"
                        + FileResource.class);
            }

            String idxFieldNameStr = implEl.getAttributeValue("indexedFieldNames");
            StringTokenizer st = new StringTokenizer(idxFieldNameStr, ",");
            int arrIdx = 0;
            String[] idxFieldNameArr = new String[st.countTokens()];
            while (st.hasMoreTokens())
            {
                idxFieldNameArr[arrIdx++] = st.nextToken().trim();
            }
           
            File csvFile = ((FileResource) extResrc).getFile();
            try(FileReader fr = new FileReader(csvFile)){
              StringTable strTable = StringTableFactory.build(
                  fr,
                  fieldDelimiter,
                  idxFieldNameArr,
                  true);
              dict = new StringTableDictionaryImpl(strTable, lookupFieldName);
            }
        }
    else
    {
      throw new Exception("Unsupported impl type:" + implType);
    }

    Iterator<?> metaFieldItr = rootDictEl.getChild("metaFields")
        .getChildren()
        .iterator();
    while (metaFieldItr.hasNext())
    {
      Element metaFieldEl = (Element) metaFieldItr.next();
      String metaFieldName = metaFieldEl.getAttributeValue("fieldName");
      dict.retainMetaData(metaFieldName);
    }

    DictionaryEngine dictEngine = new DictionaryEngine(dict, keepCase.booleanValue());

      Element excludeList = rootDictEl.getChild("excludeList");
View Full Code Here

    }

    Element lookupFieldEl = rootDictEl.getChild("lookupField");
    String lookupFieldName = lookupFieldEl.getAttributeValue("fieldName");

    Dictionary dict;

    Element implEl = (Element) rootDictEl.getChild("implementation")
        .getChildren()
        .get(0);
    String implType = implEl.getName();
    if (implType.equals("luceneImpl"))
    {
      if (!(extResrc instanceof LuceneIndexReaderResource))
      {
        throw new Exception("Expected external resource to be:"
            + LuceneIndexReaderResource.class);
      }
      IndexReader indexReader = ((LuceneIndexReaderResource) extResrc).getIndexReader();
      IndexSearcher indexSearcher = new IndexSearcher(indexReader);
      // Added 'MaxListSize' ohnlp-Bugs-3296301
      dict = new LuceneDictionaryImpl(indexSearcher, lookupFieldName, maxSizeList);
    }
    else if (implType.equals("jdbcImpl"))
    {
      String tableName = implEl.getAttributeValue("tableName");
      if (!(extResrc instanceof JdbcConnectionResource))
      {
        throw new Exception("Expected external resource to be:"
            + JdbcConnectionResource.class);
      }
      Connection conn = ((JdbcConnectionResource) extResrc).getConnection();
      dict = new JdbcDictionaryImpl(conn, tableName, lookupFieldName);
    }
        else if (implType.equals("csvImpl"))
        {
            String fieldDelimiter = implEl.getAttributeValue("delimiter");           
            if (!(extResrc instanceof FileResource))
            {
                throw new Exception("Expected external resource to be:"
                        + FileResource.class);
            }

            String idxFieldNameStr = implEl.getAttributeValue("indexedFieldNames");
            StringTokenizer st = new StringTokenizer(idxFieldNameStr, ",");
            int arrIdx = 0;
            String[] idxFieldNameArr = new String[st.countTokens()];
            while (st.hasMoreTokens())
            {
                idxFieldNameArr[arrIdx++] = st.nextToken().trim();
            }
           
            File csvFile = ((FileResource) extResrc).getFile();
            StringTable strTable = StringTableFactory.build(
                    new FileReader(csvFile),
                    fieldDelimiter,
                    idxFieldNameArr,
                    true);
            dict = new StringTableDictionaryImpl(strTable, lookupFieldName);
        }
    else
    {
      throw new Exception("Unsupported impl type:" + implType);
    }

    Iterator metaFieldItr = rootDictEl.getChild("metaFields")
        .getChildren()
        .iterator();
    while (metaFieldItr.hasNext())
    {
      Element metaFieldEl = (Element) metaFieldItr.next();
      String metaFieldName = metaFieldEl.getAttributeValue("fieldName");
      dict.retainMetaData(metaFieldName);
    }

    DictionaryEngine dictEngine = new DictionaryEngine(dict, keepCase.booleanValue());

      Element excludeList = rootDictEl.getChild("excludeList");
View Full Code Here

      }

      final Element lookupFieldEl = rootDictEl.getChild( "lookupField" );
      final String lookupFieldName = lookupFieldEl.getAttributeValue( "fieldName" );

      Dictionary dict;
      try {
         if (rootDictEl.getChild( "implementation" ).getChildren().isEmpty() ) {
            throw new ResourceAccessException( new IndexOutOfBoundsException() );
         }
         final Element implEl = (Element) rootDictEl.getChild( "implementation" ).getChildren().get( 0 );
         final String implType = implEl.getName();
         if ( implType.equals( "luceneImpl" ) ) {
            if ( !(extResrc instanceof LuceneIndexReaderResource) ) {
               throw new ResourceAccessException( "Expected external resource to be:"
                                          + LuceneIndexReaderResource.class, new Object[]{extResrc} );
            }
            final IndexReader indexReader = ((LuceneIndexReaderResource) extResrc).getIndexReader();
            final IndexSearcher indexSearcher = new IndexSearcher( indexReader );
            // Added 'MaxListSize' ohnlp-Bugs-3296301
            dict = new LuceneDictionaryImpl( indexSearcher, lookupFieldName, MAX_LIST_SIZE );
         } else if ( implType.equals( "jdbcImpl" ) ) {
            final String tableName = implEl.getAttributeValue( "tableName" );
            if ( !(extResrc instanceof JdbcConnectionResource) ) {
               throw new ResourceAccessException( "Expected external resource to be:"
                                          + JdbcConnectionResource.class, new Object[]{extResrc} );
            }
            final Connection conn = ((JdbcConnectionResource) extResrc).getConnection();
            dict = new JdbcDictionaryImpl( conn, tableName, lookupFieldName );
         } else if ( implType.equals( "csvImpl" ) ) {
            final String fieldDelimiter = implEl.getAttributeValue( "delimiter" );
            if ( !(extResrc instanceof FileResource) ) {
               throw new ResourceAccessException( "Expected external resource to be:"
                                          + FileResource.class, new Object[]{extResrc} );
            }

            final String idxFieldNameStr = implEl.getAttributeValue( "indexedFieldNames" );
            final StringTokenizer st = new StringTokenizer( idxFieldNameStr, "," );
            int arrIdx = 0;
            String[] idxFieldNameArr = new String[st.countTokens()];
            while ( st.hasMoreTokens() ) {
               idxFieldNameArr[arrIdx++] = st.nextToken().trim();
            }

            final File csvFile = ((FileResource) extResrc).getFile();
            try {
               final StringTable strTable = StringTableFactory.build( new FileReader( csvFile ),
                     fieldDelimiter, idxFieldNameArr, true );
               dict = new StringTableDictionaryImpl( strTable, lookupFieldName );
            } catch ( FileNotFoundException fnfE ) {
               throw new ResourceAccessException( "Could not open csv file", new Object[]{csvFile} );
            } catch (IOException ioE ) {
               throw new ResourceAccessException( "Could not open csv file", new Object[]{csvFile} );
            }
         } else {
            throw new ResourceAccessException( "Unsupported impl type:" + implType, new Object[]{implType} );
         }

         final List<Element> rootDictChildren = rootDictEl.getChild( "metaFields" ).getChildren();
         for ( Element metaFieldEl : rootDictChildren ) {
            final String metaFieldName = metaFieldEl.getAttributeValue( "fieldName" );
            dict.retainMetaData( metaFieldName );
         }
      } catch ( NullPointerException npE ) {
         // thrown all over this method ...
         throw new ResourceAccessException( npE );
      }
View Full Code Here

TOP

Related Classes of org.apache.ctakes.dictionary.lookup.Dictionary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.