private List < List < ConceptId > > getComputePathResultListIncludingImplicitRelations ( List < List < ConceptId > > allPaths ) { List < List < ConceptId >> extendedPaths = new ArrayList <> ( ) ; for ( List < ConceptId > currentPath : allPaths ) { boolean hasAttribute = currentPath . stream ( ) . anyMatch ( conceptID -> tx . getConcept ( conceptID ) . isAttribute ( ) ) ; if ( ! hasAttribute ) { extendedPaths . add ( currentPath ) ; } } // If there exist a path without attributes, we don't need to expand any path // as paths contain attributes would be longer after implicit relations are added int numExtensionAllowed = extendedPaths . isEmpty ( ) ? Integer . MAX_VALUE : 0 ; for ( List < ConceptId > currentPath : allPaths ) { List < ConceptId > extendedPath = new ArrayList <> ( ) ; int numExtension = 0 ; // record the number of extensions needed for the current path for ( int j = 0 ; j < currentPath . size ( ) - 1 ; j ++ ) { extendedPath . add ( currentPath . get ( j ) ) ; ConceptId resourceRelationId = Utility . getResourceEdgeId ( tx , currentPath . get ( j ) , currentPath . get ( j + 1 ) ) ; if ( resourceRelationId != null ) { numExtension ++ ; if ( numExtension > numExtensionAllowed ) break ; extendedPath . add ( resourceRelationId ) ; } } if ( numExtension == numExtensionAllowed ) { extendedPath . add ( currentPath . get ( currentPath . size ( ) - 1 ) ) ; extendedPaths . add ( extendedPath ) ; } else if ( numExtension < numExtensionAllowed ) { extendedPath . add ( currentPath . get ( currentPath . size ( ) - 1 ) ) ; extendedPaths . clear ( ) ; // longer paths are discarded extendedPaths . add ( extendedPath ) ; // update the minimum number of extensions needed so all the paths have the same length numExtensionAllowed = numExtension ; } } return extendedPaths ; }
Helper method t get the list of all shortest path but also including the implicit relations that connect entities and attributes