question: private Collection < BindingSet > generateBindingSets ( QuerySpec query , Iterable < ? extends DocumentScore > hits ) throws SailException { LinkedHashSet < BindingSet > bindingSets = new LinkedHashSet < BindingSet > ( ) ; Set < String > bindingNames = new HashSet < String > ( ) ; final String matchVar = query . getMatchesVariableName ( ) ; if ( matchVar != null ) { bindingNames . add ( matchVar ) ; } final String scoreVar = query . getScoreVariableName ( ) ; if ( scoreVar != null ) { bindingNames . add ( scoreVar ) ; } final String snippetVar = query . getSnippetVariableName ( ) ; if ( snippetVar != null ) { bindingNames . add ( snippetVar ) ; } final String propertyVar = query . getPropertyVariableName ( ) ; if ( propertyVar != null && query . getPropertyURI ( ) == null ) { bindingNames . add ( propertyVar ) ; } if ( hits != null ) { for ( DocumentScore hit : hits ) { QueryBindingSet derivedBindings = new QueryBindingSet ( ) ; SearchDocument doc = hit . getDocument ( ) ; if ( doc == null ) continue ; float score = hit . getScore ( ) ; if ( matchVar != null ) { Resource resource = getResource ( doc ) ; derivedBindings . addBinding ( matchVar , resource ) ; } if ( ( scoreVar != null ) && ( score > 0.0f ) ) derivedBindings . addBinding ( scoreVar , SearchFields . scoreToLiteral ( score ) ) ; if ( snippetVar != null || propertyVar != null ) { if ( hit . isHighlighted ( ) ) { Collection < String > fields ; if ( query . getPropertyURI ( ) != null ) { String fieldname = SearchFields . getPropertyField ( query . getPropertyURI ( ) ) ; fields = Collections . singleton ( fieldname ) ; } else { fields = doc . getPropertyNames ( ) ; } for ( String field : fields ) { Iterable < String > snippets = hit . getSnippets ( field ) ; if ( snippets != null ) { for ( String snippet : snippets ) { if ( snippet != null && ! snippet . isEmpty ( ) ) { QueryBindingSet snippetBindings = new QueryBindingSet ( derivedBindings ) ; if ( snippetVar != null ) { snippetBindings . addBinding ( snippetVar , vf . createLiteral ( snippet ) ) ; } if ( propertyVar != null && query . getPropertyURI ( ) == null ) { snippetBindings . addBinding ( propertyVar , vf . createIRI ( field ) ) ; } bindingSets . add ( snippetBindings ) ; } } } } } else { logger . warn ( "Lucene Query requests snippet, but no highlighter was generated for it, no snippets will be generated!\n{}" , query ) ; bindingSets . add ( derivedBindings ) ; } } else { bindingSets . add ( derivedBindings ) ; } } } return new BindingSetCollection ( bindingNames , bindingSets ) ; }
target:  This method generates bindings from the given result of a Lucene query.