All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aksw.sparqlify.database.PatriciaPrefixMapStoreAccessor Maven / Gradle / Ivy

There is a newer version: 3.17.0-1
Show newest version
package org.aksw.sparqlify.database;

//public class PatriciaPrefixMapStoreAccessor
//    implements MapStoreAccessor
//{
//    public static Set> supportedConstraintClasses = new HashSet>();
//
//    static
//    {
//        supportedConstraintClasses.add(EqualsConstraint.class);
//        supportedConstraintClasses.add(StartsWithConstraint.class);
//        supportedConstraintClasses.add(IsPrefixOfConstraint.class);
//    }
//
//    public Set> getSupportedConstraintClasses() {
//        return supportedConstraintClasses;
//    }
//
//
//    private int indexColumn;
//    private Transformer> prefixExtractor;
//
//    public PatriciaPrefixMapStoreAccessor(int[] indexColumns, Transformer> prefixExtractor) {
//        if(indexColumns.length != 1) {
//            throw new RuntimeException("Prefix index can only operate on single columns");
//        }
//
//        this.indexColumn = indexColumns[0];
//        this.prefixExtractor = prefixExtractor;
//    }
//
//    /**
//     * We assume that
//     * . only classes that are in supportedConstraintClasses are passed to this method.
//     * . only constraints for which the index has the right columns are passed
//     *
//     * This method should only be used by the engine
//     *
//     * @param constraints
//     * @return
//     */
//    /*
//    @Override
//    public Collection lookup(Object store, List constraints)
//    {
//        return lookup((NavigableMap)store, constraints);
//    }*/
//
//
//    @Override
//    public void put(Object store, List row, Object value) {
//        /*
//        PatriciaTrie x;
//        x.prefixMap(arg0)
//        */
//
//
//        put((PatriciaTrie)store, row, value);
//    }
//
//    public void put(PatriciaTrie map, List row, Object value) {
//        map.put((String)row.get(indexColumn), value);
//    }
//
//    ///*protected PrefixMap
//
//    /**
//     * The constraints given as arguments are interpreted as conjunctions.
//     * The set of prefixes within a constraint is interpreted as a disjunction.
//     *
//     *
//     * @param constraints
//     */
//    public Collection lookup(Object store, Constraint constraint) {
//        PatriciaTrie map = (PatriciaTrie)store;
//
//        if(constraint instanceof IsPrefixOfConstraint) {
//            return lookup(map, (IsPrefixOfConstraint)constraint);
//        } else if(constraint instanceof StartsWithConstraint) {
//            return lookup(map, (StartsWithConstraint)constraint);
//        } else if(constraint instanceof EqualsConstraint) {
//            return lookup(map, (EqualsConstraint)constraint);
//        } else {
//            throw new RuntimeException("Could not handle constraint " + constraint);
//        }
//    }
//
//    public Collection lookup(PatriciaTrie map, EqualsConstraint constraint) {
//        return Collections.singleton(map.get(constraint.getValue()));
//    }
//
//    public Collection lookup(PatriciaTrie map, StartsWithConstraint constraint) {
//        if(!constraint.isInclusive()) {
//            throw new RuntimeException("Patricia tree does not support 'non-inclusive' constraint, and I haven't hacked that in yet");
//        }
//
//        return map.prefixMap(constraint.getPrefix()).values();
//    }
//
//    public Collection lookup(PatriciaTrie map, IsPrefixOfConstraint constraint) {
//        String lookup = constraint.getValue();
//        if(!constraint.isInclusive()) {
//            int n = lookup.length();
//            if(n == 0) {
//                return Collections.emptySet();
//            } else {
//                lookup.substring(0, n - 1);
//            }
//        }
//
//        //Object o= map.get("");
//        if(true) {
//            throw new RuntimeException("Either the patricia tree impl is broken, or I misunderstood something about it..., but the prefix map does not contain all prefixes of a given string");
//        }
//
//        Collection result = map.prefixMap(lookup).values();
//        return result;
//
//        //return StringUtils.getAllPrefixes(constraint.getValue(), constraint.isInclusive(), map).values();
//    }
//
//    @Override
//    public Object get(Object store, List row) {
//        return get((PatriciaTrie)store, row);
//    }
//
//    public Object get(PatriciaTrie map, List row) {
//        return map.get(row.get(indexColumn));
//    }
//
//    @SuppressWarnings("unchecked")
//    @Override
//    public Collection list(Object store) {
//        return ((PatriciaTrie)store).values();
//    }
//
//
//    @Override
//    public PatriciaTrie createStore() {
//        return new PatriciaTrie(StringKeyAnalyzer.BYTE);
//    }
//
//
//}