Examples of TextIndexException


Examples of org.apache.jena.query.text.TextIndexException

    }
   
    private Analyzer analyzerWithStopWords(Resource root) {
      RDFNode node = root.getProperty(TextVocab.pStopWords).getObject();
      if (! node.isResource()) {
        throw new TextIndexException("text:stopWords property takes a list as a value : " + node);
      }
      CharArraySet stopWords = toCharArraySet((Resource) node);
      return new StandardAnalyzer(TextIndexLucene.VER, stopWords);
    }
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

      List<String> result = new ArrayList<String>();
      Resource current = list;
      while (current != null && ! current.equals(RDF.nil)){
        Statement stmt = current.getProperty(RDF.first);
        if (stmt == null) {
          throw new TextIndexException("stop word list not well formed");
        }
        RDFNode node = stmt.getObject();
        if (! node.isLiteral()) {
          throw new TextIndexException("stop word is not a literal : " + node);
        }
        result.add(((Literal)node).getLexicalForm());
        stmt = current.getProperty(RDF.rest);
        if (stmt == null) {
          throw new TextIndexException("stop word list not terminated by rdf:nil");
        }
        node = stmt.getObject();
        if (! node.isResource()) {
          throw new TextIndexException("stop word list node is not a resource : " + node);
        }
        current = (Resource) node;
      }
      return result;
    }
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

        QueryExecution qexec1 = QueryExecutionFactory.create(query1, model) ;
        ResultSet rs1 = qexec1.execSelect() ;
        List<QuerySolution> results = ResultSetFormatter.toList(rs1) ;
        if ( results.size() == 0 ) {
            Log.warn(this, "Failed to find a valid EntityMap for : "+root) ;
            throw new TextIndexException("Failed to find a valid EntityMap for : "+root) ;
        }
       
        if ( results.size() !=1 )  {
            Log.warn(this, "Multiple matches for EntityMap for : "+root) ;
            throw new TextIndexException("Multiple matches for EntityMap for : "+root) ;
        }
       
        QuerySolution qsol1 = results.get(0) ;
        String entityField = qsol1.getLiteral("entityField").getLexicalForm() ;
        String graphField = qsol1.contains("graphField") ? qsol1.getLiteral("graphField").getLexicalForm() : null;
        String defaultField = qsol1.contains("dftField") ? qsol1.getLiteral("dftField").getLexicalForm() : null ;
             
        MultiMap<String, Node> mapDefs = MultiMap.createMapList() ;
        Map<String, Analyzer> analyzerDefs = new HashMap<String, Analyzer>();
       
        Statement listStmt = root.getProperty(TextVocab.pMap);
        while (listStmt != null) {
          RDFNode n = listStmt.getObject();
          if (! n.isResource()) {
            throw new TextIndexException("Text list node is not a resource : " + n);
          }
          Resource listResource = (Resource) n;
          if (listResource.equals(RDF.nil)) {
            break// end of the list
          }
         
          Statement listEntryStmt = listResource.getProperty(RDF.first);
          if (listEntryStmt == null) {
            throw new TextIndexException("Text map list is not well formed.  No rdf:first property");
          }
          n = listEntryStmt.getObject();
          if (! n.isResource()) {
            throw new TextIndexException("Text map list entry is not a resource : " + n);
          }
          Resource listEntry = (Resource) n;
         
          Statement fieldStatement = listEntry.getProperty(TextVocab.pField);
          if (fieldStatement == null) {
            throw new TextIndexException("Text map entry has no field property");
          }
          n = fieldStatement.getObject();
          if (! n.isLiteral()) {
            throw new TextIndexException("Text map entry field property has no literal value : " + n);
          }
          String field = ((Literal)n).getLexicalForm();
         
          Statement predicateStatement = listEntry.getProperty(TextVocab.pPredicate);
          if (predicateStatement == null) {
            throw new TextIndexException("Text map entry has no predicate property");
          }
          n = predicateStatement.getObject();
          if (! n.isURIResource()) {
            throw new TextIndexException("Text map entry predicate property has non resource value : " + n);
          }
          Resource predicate = (Resource) n;
          mapDefs.put(field, predicate.asNode()) ;
         
          Statement analyzerStatement = listEntry.getProperty(TextVocab.pAnalyzer);
          if (analyzerStatement != null) {
            n = analyzerStatement.getObject();
            if (! n.isResource()) {
              throw new TextIndexException("Text map entry analyzer property is not a resource : " + n);
            }
            Resource analyzerResource = (Resource) n;
            Analyzer analyzer = (Analyzer) a.open(analyzerResource);
            analyzerDefs.put(field, analyzer);
          }
         
          // move on to the next element in the list
          listStmt = listResource.getProperty(RDF.rest);
        }

        // Primary field/predicate
        if ( defaultField != null ) {
            Collection<Node> c = mapDefs.get(defaultField) ;
            if ( c == null )
                throw new TextIndexException("No definition of primary field '"+defaultField+"'") ;
        }
       
        EntityDefinition docDef = new EntityDefinition(entityField, defaultField, graphField) ;
        for ( String f : mapDefs.keys() ) {
            for ( Node p : mapDefs.get(f))
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

    @Override
    public TextIndex open(Assembler a, Resource root, Mode mode) {
        try {
            if ( !GraphUtils.exactlyOneProperty(root, pDirectory) )
                throw new TextIndexException("No 'text:directory' property on " + root) ;

            Directory directory ;
            RDFNode n = root.getProperty(pDirectory).getObject() ;
            if ( n.isLiteral() ) {
                if ( !"mem".equals(n.asLiteral().getLexicalForm()) )
                    throw new TextIndexException("No 'text:directory' property on " + root
                                                 + " is a literal and not \"mem\"") ;
                directory = new RAMDirectory() ;
            } else {
                Resource x = n.asResource() ;
                String path = IRILib.IRIToFilename(x.getURI()) ;
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

    @Override
    public TextIndex open(Assembler a, Resource root, Mode mode) {
        String uri = GraphUtils.getResourceValue(root, pServer).getURI() ;
        SolrServer server ;
        if ( uri.startsWith("embedded:") ) {
            throw new TextIndexException("Embedded Solr server not supported (change code and dependencies to enable)") ;
//            String coreName = uri.substring("embedded:".length()) ;
//            CoreContainer.Initializer initializer = new CoreContainer.Initializer();
//            CoreContainer coreContainer ;
//            try { coreContainer = initializer.initialize() ; }
//            catch (Exception e) { throw new TextIndexException("Filed to initialize embedded solr", e) ; }
//            server = new EmbeddedSolrServer(coreContainer, coreName);
        }
        else if ( uri.startsWith("http://") )
            server = new HttpSolrServer( uri );
        else
            throw new TextIndexException("URI for the server must begin 'http://'") ;
       
        Resource r = GraphUtils.getResourceValue(root, pEntityMap) ;
        EntityDefinition docDef = (EntityDefinition)a.open(r) ;
        return TextDatasetFactory.createSolrIndex(server, docDef) ;
    }
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

    }
   
    private Analyzer analyzerWithStopWords(Resource root) {
      RDFNode node = root.getProperty(TextVocab.pStopWords).getObject();
      if (! node.isResource()) {
        throw new TextIndexException("text:stopWords property takes a list as a value : " + node);
      }
      CharArraySet stopWords = toCharArraySet((Resource) node);
      return new StandardAnalyzer(TextIndexLucene.VER, stopWords);
    }
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

      List<String> result = new ArrayList<>();
      Resource current = list;
      while (current != null && ! current.equals(RDF.nil)){
        Statement stmt = current.getProperty(RDF.first);
        if (stmt == null) {
          throw new TextIndexException("stop word list not well formed");
        }
        RDFNode node = stmt.getObject();
        if (! node.isLiteral()) {
          throw new TextIndexException("stop word is not a literal : " + node);
        }
        result.add(((Literal)node).getLexicalForm());
        stmt = current.getProperty(RDF.rest);
        if (stmt == null) {
          throw new TextIndexException("stop word list not terminated by rdf:nil");
        }
        node = stmt.getObject();
        if (! node.isResource()) {
          throw new TextIndexException("stop word list node is not a resource : " + node);
        }
        current = (Resource) node;
      }
      return result;
    }
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

        QueryExecution qexec1 = QueryExecutionFactory.create(query1, model) ;
        ResultSet rs1 = qexec1.execSelect() ;
        List<QuerySolution> results = ResultSetFormatter.toList(rs1) ;
        if ( results.size() == 0 ) {
            Log.warn(this, "Failed to find a valid EntityMap for : "+root) ;
            throw new TextIndexException("Failed to find a valid EntityMap for : "+root) ;
        }
       
        if ( results.size() !=1 )  {
            Log.warn(this, "Multiple matches for EntityMap for : "+root) ;
            throw new TextIndexException("Multiple matches for EntityMap for : "+root) ;
        }
       
        QuerySolution qsol1 = results.get(0) ;
        String entityField = qsol1.getLiteral("entityField").getLexicalForm() ;
        String graphField = qsol1.contains("graphField") ? qsol1.getLiteral("graphField").getLexicalForm() : null;
        String defaultField = qsol1.contains("dftField") ? qsol1.getLiteral("dftField").getLexicalForm() : null ;
             
        MultiMap<String, Node> mapDefs = MultiMap.createMapList() ;
        Map<String, Analyzer> analyzerDefs = new HashMap<>();
       
        Statement listStmt = root.getProperty(TextVocab.pMap);
        while (listStmt != null) {
          RDFNode n = listStmt.getObject();
          if (! n.isResource()) {
            throw new TextIndexException("Text list node is not a resource : " + n);
          }
          Resource listResource = (Resource) n;
          if (listResource.equals(RDF.nil)) {
            break// end of the list
          }
         
          Statement listEntryStmt = listResource.getProperty(RDF.first);
          if (listEntryStmt == null) {
            throw new TextIndexException("Text map list is not well formed.  No rdf:first property");
          }
          n = listEntryStmt.getObject();
          if (! n.isResource()) {
            throw new TextIndexException("Text map list entry is not a resource : " + n);
          }
          Resource listEntry = (Resource) n;
         
          Statement fieldStatement = listEntry.getProperty(TextVocab.pField);
          if (fieldStatement == null) {
            throw new TextIndexException("Text map entry has no field property");
          }
          n = fieldStatement.getObject();
          if (! n.isLiteral()) {
            throw new TextIndexException("Text map entry field property has no literal value : " + n);
          }
          String field = ((Literal)n).getLexicalForm();
         
          Statement predicateStatement = listEntry.getProperty(TextVocab.pPredicate);
          if (predicateStatement == null) {
            throw new TextIndexException("Text map entry has no predicate property");
          }
          n = predicateStatement.getObject();
          if (! n.isURIResource()) {
            throw new TextIndexException("Text map entry predicate property has non resource value : " + n);
          }
          Resource predicate = (Resource) n;
          mapDefs.put(field, predicate.asNode()) ;
         
          Statement analyzerStatement = listEntry.getProperty(TextVocab.pAnalyzer);
          if (analyzerStatement != null) {
            n = analyzerStatement.getObject();
            if (! n.isResource()) {
              throw new TextIndexException("Text map entry analyzer property is not a resource : " + n);
            }
            Resource analyzerResource = (Resource) n;
            Analyzer analyzer = (Analyzer) a.open(analyzerResource);
            analyzerDefs.put(field, analyzer);
          }
         
          // move on to the next element in the list
          listStmt = listResource.getProperty(RDF.rest);
        }

        // Primary field/predicate
        if ( defaultField != null ) {
            Collection<Node> c = mapDefs.get(defaultField) ;
            if ( c == null )
                throw new TextIndexException("No definition of primary field '"+defaultField+"'") ;
        }
       
        EntityDefinition docDef = new EntityDefinition(entityField, defaultField, graphField) ;
        for ( String f : mapDefs.keys() ) {
            for ( Node p : mapDefs.get(f))
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

        QueryExecution qexec1 = QueryExecutionFactory.create(query1, model) ;
        ResultSet rs1 = qexec1.execSelect() ;
        List<QuerySolution> results = ResultSetFormatter.toList(rs1) ;
        if ( results.size() == 0 ) {
            //Log.warn(this, "Failed to find a valid EntityMap for : "+root) ;
            throw new TextIndexException("Failed to find a valid EntityMap for : "+root) ;
        }
       
        if ( results.size() !=1 )  {
            Log.warn(this, "Multiple matches for EntityMap for : "+root) ;
            throw new TextIndexException("Multiple matches for EntityMap for : "+root) ;
        }
       
        QuerySolution qsol1 = results.get(0) ;
        String entityField = qsol1.getLiteral("entityField").getLexicalForm() ;
       
        String defaultField = qsol1.contains("dftField") ? qsol1.getLiteral("dftField").getLexicalForm() : null ;
       
        String qs2 = StrUtils.strjoinNL("SELECT * { ?map list:member [ :field ?field ; :predicate ?predicate ] }") ;
        Query query2 = QueryFactory.create(prologue+" "+qs2) ;
        QueryExecution qexec2 = QueryExecutionFactory.create(query2, model, qsol1) ;
        ResultSet rs2 = qexec2.execSelect() ;
        List<QuerySolution> mapEntries = ResultSetFormatter.toList(rs2) ;
       
        MultiMap<String, Node> mapDefs = MultiMap.createMapList() ;
        for ( QuerySolution qsol : mapEntries ) {
            String field =  qsol.getLiteral("field").getLexicalForm() ;
            Resource p = qsol.getResource("predicate") ;
            mapDefs.put(field, p.asNode()) ;
        }
       
        // Primary field/predicate
        if ( defaultField != null ) {
            Collection<Node> c = mapDefs.get(defaultField) ;
            if ( c == null )
                throw new TextIndexException("No definition of primary field '"+defaultField+"'") ;
        }
       
       
        EntityDefinition docDef = new EntityDefinition(entityField, defaultField) ;
        for ( String f : mapDefs.keys() ) {
View Full Code Here

Examples of org.apache.jena.query.text.TextIndexException

    {
        String uri = GraphUtils.getResourceValue(root, pServer).getURI() ;
        SolrServer server ;
        if ( uri.startsWith("embedded:") )
        {
            throw new TextIndexException("Embedded Solr server not supported (change code and dependencies to enable)") ;
//            String coreName = uri.substring("embedded:".length()) ;
//            CoreContainer.Initializer initializer = new CoreContainer.Initializer();
//            CoreContainer coreContainer = initializer.initialize();
//            server = new EmbeddedSolrServer(coreContainer, coreName);
        }
        else if ( uri.startsWith("http://") )
            server = new HttpSolrServer( uri );
        else
            throw new TextIndexException("URI for the server must begin 'http://'") ;
       
        Resource r = GraphUtils.getResourceValue(root, pEntityMap) ;
        EntityDefinition docDef = (EntityDefinition)a.open(r) ;
        return TextDatasetFactory.createSolrIndex(server, docDef) ;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.