public class NE { public Integer startIndex; public Integer endIndex; } public class CustomComparator implements Comparator<NE> { public int compare(NE n1, NE n2) { return n1.startIndex.compareTo(n2.startIndex); } } ArrayList<NE> NEList = getIndexes(); Collections.sort(NEList, ner.new CustomComparator()); String finalString = 'John is a student. He is also a researcher. He is also a human.'; for(int i=NEList.size()-1;i>=0;i--){ NE ne = ner.new NE(); ne = NEList.get(i); finalString = new StringBuilder(finalString).replace(ne.startIndex, ne.endIndex, 'x').toString(); } System.out.println(finalString);
/** * Unit test for {@link NE#get(IBindingSet)} */ public void testGet () { final Var<?> x = Var.var ( "x" ) ; final Var<?> y = Var.var ( "y" ) ; final Var<?> vars [] = new Var<?> [] { x, y } ; final NE op = new NE ( x, y ) ; final IBindingSet eq = new ListBindingSet ( vars, new IConstant [] { new Constant<String> ( "1" ), new Constant<String> ( "1" ) } ) ; final IBindingSet ne = new ListBindingSet ( vars, new IConstant [] { new Constant<String> ( "1" ), new Constant<String> ( "2" ) } ) ; final IBindingSet nb = new ListBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<String> ( "1" ) } ) ; assertTrue ( op.get ( ne ) ) ; assertFalse ( op.get ( eq ) ) ; assertTrue ( op.get ( nb ) ) ; } }
public Boolean get(final IBindingSet s) { // get binding for "x". final IConstant<?> x = s.get((IVariable<?>) get(0)/* x */); if (x == null) return true; // not yet bound. // get binding for "y". final IConstant<?> y = s.get((IVariable<?>) get(1)/* y */); if (y == null) return true; // not yet bound. return !x.equals(y); }
public Boolean get(final IBindingSet s) { // get binding for "x". final IConstant<?> x = s.get((IVariable<?>) get(0)/* x */); if (x == null) return true; // not yet bound. // get binding for "y". final IConstant<?> y = s.get((IVariable<?>) get(1)/* y */); if (y == null) return true; // not yet bound. return !x.equals(y); }
/** * Unit test for {@link NE#NE(IVariable,IVariable)} */ public void testConstructor () { try { assertTrue ( null != new NE ( null, Var.var ( "y" ) ) ) ; fail ( "IllegalArgumentException expected, lhs was null" ) ; } catch ( IllegalArgumentException e ) {} try { assertTrue ( null != new NE ( Var.var ( "x" ), null ) ) ; fail ( "IllegalArgumentException expected, rhs was null" ) ; } catch ( IllegalArgumentException e ) {} try { assertTrue ( null != new NE ( Var.var ( "x" ), Var.var ( "x" ) ) ) ; fail ( "IllegalArgumentException expected, lhs identical to rhs" ) ; } catch ( IllegalArgumentException e ) {} assertTrue ( null != new NE ( Var.var ( "x" ), Var.var ( "y" ) ) ) ; }
/** * Unit test for {@link NE#get(IBindingSet)} */ public void testGet () { final Var<?> x = Var.var ( "x" ) ; final Var<?> y = Var.var ( "y" ) ; final Var<?> vars [] = new Var<?> [] { x, y } ; final NE op = new NE ( x, y ) ; final IBindingSet eq = new ListBindingSet ( vars, new IConstant [] { new Constant<String> ( "1" ), new Constant<String> ( "1" ) } ) ; final IBindingSet ne = new ListBindingSet ( vars, new IConstant [] { new Constant<String> ( "1" ), new Constant<String> ( "2" ) } ) ; final IBindingSet nb = new ListBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<String> ( "1" ) } ) ; assertTrue ( op.get ( ne ) ) ; assertFalse ( op.get ( eq ) ) ; assertTrue ( op.get ( nb ) ) ; } }
/** * Unit test for {@link NE#NE(IVariable,IVariable)} */ public void testConstructor () { try { assertTrue ( null != new NE ( null, Var.var ( "y" ) ) ) ; fail ( "IllegalArgumentException expected, lhs was null" ) ; } catch ( IllegalArgumentException e ) {} try { assertTrue ( null != new NE ( Var.var ( "x" ), null ) ) ; fail ( "IllegalArgumentException expected, rhs was null" ) ; } catch ( IllegalArgumentException e ) {} try { assertTrue ( null != new NE ( Var.var ( "x" ), Var.var ( "x" ) ) ) ; fail ( "IllegalArgumentException expected, lhs identical to rhs" ) ; } catch ( IllegalArgumentException e ) {} assertTrue ( null != new NE ( Var.var ( "x" ), Var.var ( "y" ) ) ) ; }
/** * @param vocab */ public RuleOwlSameAs1b(String relationName, Vocabulary vocab) { super( "owlSameAs1b",// new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("z")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("y")),// new SPOPredicate(relationName,var("y"), vocab.getConstant(OWL.SAMEAS), var("z"))// }, new IConstraint[] { Constraint.wrap(new NE(var("x"),var("y"))), Constraint.wrap(new NE(var("y"),var("z"))), Constraint.wrap(new NE(var("x"),var("z"))), } ); }
/** * @param vocab */ public RuleOwlSameAs1b(String relationName, Vocabulary vocab) { super( "owlSameAs1b",// new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("z")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("y")),// new SPOPredicate(relationName,var("y"), vocab.getConstant(OWL.SAMEAS), var("z"))// }, new IConstraint[] { Constraint.wrap(new NE(var("x"),var("y"))), Constraint.wrap(new NE(var("y"),var("z"))), Constraint.wrap(new NE(var("x"),var("z"))), } ); }
public RuleRdfs11(String relationName, Vocabulary vocab) { super( "rdfs11",// new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBCLASSOF), var("x")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBCLASSOF), var("v")),// new SPOPredicate(relationName,var("v"), vocab.getConstant(RDFS.SUBCLASSOF), var("x")) // }, new IConstraint[] { Constraint.wrap(new NE(var("u"),var("v"))), Constraint.wrap(new NE(var("v"),var("x"))) }); }
public RuleRdfs05(String relationName, Vocabulary vocab) { super( "rdfs05",// new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("x")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("v")),// new SPOPredicate(relationName,var("v"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("x")) // }, new IConstraint[] { Constraint.wrap(new NE(var("u"),var("v"))), Constraint.wrap(new NE(var("v"),var("x"))) }); }
public RuleRdfs11(String relationName, Vocabulary vocab) { super( "rdfs11",// new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBCLASSOF), var("x")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBCLASSOF), var("v")),// new SPOPredicate(relationName,var("v"), vocab.getConstant(RDFS.SUBCLASSOF), var("x")) // }, new IConstraint[] { Constraint.wrap(new NE(var("u"),var("v"))), Constraint.wrap(new NE(var("v"),var("x"))) }); }
public RuleRdfs05(String relationName, Vocabulary vocab) { super( "rdfs05",// new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("x")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("v")),// new SPOPredicate(relationName,var("v"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("x")) // }, new IConstraint[] { Constraint.wrap(new NE(var("u"),var("v"))), Constraint.wrap(new NE(var("v"),var("x"))) }); }
/** * @param vocab */ public RuleOwlTransitiveProperty1(String relationName, Vocabulary vocab) { super( "owlTransitiveProperty1",// new SPOPredicate(relationName,var("x"), var("a"), var("z")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("a"), vocab.getConstant(RDF.TYPE), vocab.getConstant(OWL.TRANSITIVEPROPERTY)),// new SPOPredicate(relationName,var("x"), var("a"), var("y")),// new SPOPredicate(relationName,var("y"), var("a"), var("z"))// }, new IConstraint[] { Constraint.wrap(new NE(var("x"),var("y"))), Constraint.wrap(new NE(var("y"),var("z"))), Constraint.wrap(new NE(var("x"),var("z"))), } ); }
/** * @param vocab */ public RuleOwlTransitiveProperty1(String relationName, Vocabulary vocab) { super( "owlTransitiveProperty1",// new SPOPredicate(relationName,var("x"), var("a"), var("z")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("a"), vocab.getConstant(RDF.TYPE), vocab.getConstant(OWL.TRANSITIVEPROPERTY)),// new SPOPredicate(relationName,var("x"), var("a"), var("y")),// new SPOPredicate(relationName,var("y"), var("a"), var("z"))// }, new IConstraint[] { Constraint.wrap(new NE(var("x"),var("y"))), Constraint.wrap(new NE(var("y"),var("z"))), Constraint.wrap(new NE(var("x"),var("z"))), } ); }
/** * @param vocab */ public RuleOwlSameAs1(String relationName, Vocabulary vocab) { super( "owlSameAs1",// new SPOPredicate(relationName,var("y"), vocab.getConstant(OWL.SAMEAS), var("x")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("y"))// }, new IConstraint[] { Constraint.wrap(new NE(var("x"),var("y"))) } ); }
public TestRuleRdfs9(String relation) { super( "rdfs9",// new P(relation,var("v"), rdfType, var("x")), // new IPredicate[] {// new P(relation, var("u"), rdfsSubClassOf, var("x")),// new P(relation, var("v"), rdfType, var("u")) // },// new IConstraint[] { Constraint.wrap(new NE(var("u"),var("x"))) } ); }
public TestRuleRdfs9(String relation) { super( "rdfs9",// new P(relation,var("v"), rdfType, var("x")), // new IPredicate[] {// new P(relation, var("u"), rdfsSubClassOf, var("x")),// new P(relation, var("v"), rdfType, var("u")) // },// new IConstraint[] { Constraint.wrap(new NE(var("u"),var("x"))) } ); }
public TestRuleRdfs9(String relation) { super( "rdfs9",// new P(relation,var("v"), rdfType, var("x")), // new IPredicate[] {// new P(relation, var("u"), rdfsSubClassOf, var("x")),// new P(relation, var("v"), rdfType, var("u")) // },// new IConstraint[] { Constraint.wrap(new NE(var("u"),var("x"))) } ); }
/** * @param vocab */ public RuleOwlSameAs1(String relationName, Vocabulary vocab) { super( "owlSameAs1",// new SPOPredicate(relationName,var("y"), vocab.getConstant(OWL.SAMEAS), var("x")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("y"))// }, new IConstraint[] { Constraint.wrap(new NE(var("x"),var("y"))) } ); }