Skip to content

Commit 6b3d383

Browse files
committed
增加了专门用于删除非推理结果的三元组的功能
和RDFSOWLReasoner
1 parent 095e5f2 commit 6b3d383

File tree

4 files changed

+99
-19
lines changed

4 files changed

+99
-19
lines changed

mrj-0.1/src/cn/edu/neu/mitt/mrj/io/dbs/CassandraDB.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import java.util.Map;
2424
import java.util.Set;
2525

26-
import org.apache.cassandra.cql3.QueryProcessor;
27-
import org.apache.cassandra.cql3.UntypedResultSet;
28-
import org.apache.cassandra.db.marshal.TupleType;
2926
import org.apache.cassandra.exceptions.RequestExecutionException;
3027
import org.apache.cassandra.thrift.Cassandra;
3128
import org.apache.cassandra.thrift.Column;
@@ -60,11 +57,9 @@
6057
import com.datastax.driver.core.Statement;
6158
//modified cassandra java 2.0.5
6259
import com.datastax.driver.core.TupleValue;
60+
import com.datastax.driver.core.querybuilder.Delete.Where;
6361
import com.datastax.driver.core.querybuilder.QueryBuilder;
64-
65-
6662
//modified
67-
import org.apache.cassandra.thrift.CassandraServer;
6863

6964

7065
/**
@@ -582,7 +577,7 @@ public Map<Long, Collection<Long>> loadMapIntoMemory(Set<Integer> filters) throw
582577
return loadMapIntoMemory(filters, false);
583578
}
584579

585-
// 返回的key就是triple的subject,value是object
580+
// ���ص�key����triple��subject��value��object
586581
public Map<Long, Collection<Long>> loadMapIntoMemory(Set<Integer> filters, boolean inverted) throws IOException, InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException {
587582
long startTime = System.currentTimeMillis();
588583

@@ -648,7 +643,18 @@ public void createIndexOnRule() throws InvalidRequestException, UnavailableExcep
648643
client.execute_cql3_query(ByteBufferUtil.bytes(query), Compression.NONE, ConsistencyLevel.ONE);
649644
}
650645

651-
646+
// Added by WuGang 2015-06-08
647+
public static void removeOriginalTriples(){
648+
SimpleClientDataStax scds = new SimpleClientDataStax();
649+
scds.connect(DEFAULT_HOST);
650+
651+
Where dQuery = QueryBuilder.delete()
652+
.from(KEYSPACE, COLUMNFAMILY_JUSTIFICATIONS)
653+
.where(QueryBuilder.eq(COLUMN_RULE, ByteBufferUtil.bytes(0)));
654+
scds.getSession().execute(dQuery);
655+
656+
scds.close();
657+
}
652658

653659
public static void main(String[] args) {
654660
try {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package cn.edu.neu.mitt.mrj.reasoner;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import cn.edu.neu.mitt.mrj.reasoner.owl.OWLReasoner;
7+
import cn.edu.neu.mitt.mrj.reasoner.rdfs.RDFSReasoner;
8+
9+
public class RDFSOWLReasoner {
10+
11+
protected static Logger log = LoggerFactory.getLogger(RDFSOWLReasoner.class);
12+
13+
static int step = 0;
14+
15+
private static void parseArgs(String[] args) {
16+
17+
for(int i=0;i<args.length; ++i) {
18+
if (args[i].equalsIgnoreCase("--startingStep")) {
19+
RDFSOWLReasoner.step = Integer.valueOf(args[++i]);
20+
}
21+
22+
}
23+
}
24+
25+
public static void main(String[] args) {
26+
if (args.length < 1) {
27+
System.out.println("USAGE: RDFSOWLReasoner [pool path] [options]");
28+
return;
29+
}
30+
31+
parseArgs(args);
32+
33+
RDFSReasoner rdfsReasoner = new RDFSReasoner();
34+
OWLReasoner owlReasoner = new OWLReasoner();
35+
try {
36+
long totalDerivation = 0;
37+
boolean continueDerivation = true;
38+
long startTime = System.currentTimeMillis();
39+
long rdfsDerivation = 0;
40+
long owlDerivation = 0;
41+
boolean firstLoop = true;
42+
43+
while (continueDerivation) {
44+
//Do RDFS reasoning
45+
if (owlDerivation == 0 && !firstLoop) {
46+
rdfsDerivation = 0;
47+
} else {
48+
RDFSReasoner.step = RDFSOWLReasoner.step;
49+
rdfsDerivation = rdfsReasoner.launchDerivation(args);
50+
}
51+
52+
//Do OWL reasoning
53+
if (rdfsDerivation == 0 && !firstLoop) {
54+
owlDerivation = 0;
55+
} else {
56+
OWLReasoner.step = RDFSReasoner.step;
57+
owlDerivation = owlReasoner.launchClosure(args);
58+
RDFSOWLReasoner.step = OWLReasoner.step;
59+
}
60+
totalDerivation += owlDerivation + rdfsDerivation;
61+
continueDerivation = (owlDerivation + rdfsDerivation) > 0;
62+
firstLoop = false;
63+
}
64+
// log.info("Number triples derived: " + totalDerivation);
65+
// log.info("Time derivation: " + (System.currentTimeMillis() - startTime));
66+
System.out.println("Number triples derived: " + totalDerivation);
67+
System.out.println("Time derivation: " + (System.currentTimeMillis() - startTime));
68+
} catch (Exception e) {
69+
log.error(e.getMessage());
70+
e.printStackTrace();
71+
}
72+
}
73+
74+
}

mrj-0.1/src/cn/edu/neu/mitt/mrj/reasoner/owl/OWLEquivalenceSCSPMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ public void setup(Context context) throws IOException {
9595
Set<Integer> filters = new HashSet<Integer>();
9696
filters.add(TriplesUtils.SCHEMA_TRIPLE_SUBPROPERTY);
9797
//modified 2015/5/31
98-
//db.loadSetIntoMemory(subpropSchemaTriples, filters, -1);
98+
db.loadSetIntoMemory(subpropSchemaTriples, filters, -1);
9999
}
100100

101101
if (subclassSchemaTriples == null) {
102102
subclassSchemaTriples = new HashSet<Long>();
103103
Set<Integer> filters = new HashSet<Integer>();
104104
filters.add(TriplesUtils.SCHEMA_TRIPLE_SUBCLASS);
105105
//modified 2015/5/31
106-
//db.loadSetIntoMemory(subclassSchemaTriples, filters, -1);
106+
db.loadSetIntoMemory(subclassSchemaTriples, filters, -1);
107107
}
108108
db.CassandraDBClose();
109109
//modified 2015/5/31

mrj-0.1/src/cn/edu/neu/mitt/mrj/reasoner/owl/OWLReasoner.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class OWLReasoner extends Configured implements Tool {
3737
public static final String OWL_PROP_INHERITANCE_TMP = "/dir-tmp-prop-inheritance/";
3838
public static final String OWL_PROP_INHERITANCE = "/dir-prop-inheritance/";
3939
public static final String OWL_TRANSITIVITY_BASE = OWL_PROP_INHERITANCE_TMP + "dir-transitivity-base/";
40-
public static final String OWL_TRANSITIVITY = "dir-transitivity/"; // Added by WuGang 2010-08-25,新加的目录
40+
public static final String OWL_TRANSITIVITY = "dir-transitivity/"; // Added by WuGang 2010-08-25���¼ӵ�Ŀ¼
4141

4242
public static final String OWL_SYNONYMS_TABLE = "dir-table-synonyms/";
4343
public static final String OWL_SYNONYMS_TABLE_NEW = "_table_synonyms_new/";
@@ -154,15 +154,15 @@ public long launchClosure(String[] args) throws IOException, InterruptedExceptio
154154
break;
155155
currentStep++;
156156
long hasValueDerivation = inferHasValueStatements(args);
157-
System.out.println("-----------inferHasValueStatements结束");
157+
System.out.println("-----------inferHasValueStatements����");
158158
derivedTriples += hasValueDerivation;
159159
if (hasValueDerivation > 0) lastDerivationStep = currentStep;
160160

161161
if (!firstCycle && lastDerivationStep == (currentStep - 4))
162162
break;
163163
currentStep++;
164164
long someAllDerivation = inferSomeAndAllValuesStatements(args);
165-
System.out.println("-----------inferSomeAndAllValuesStatements结束");
165+
System.out.println("-----------inferSomeAndAllValuesStatements����");
166166
derivedTriples += someAllDerivation;
167167
if (someAllDerivation > 0) lastDerivationStep = currentStep;
168168

@@ -230,7 +230,7 @@ private long inferPropertiesInheritance(String[] args) throws IOException, Inter
230230
private long inferTransitivityStatements(String[] args)
231231
throws IOException, InterruptedException, ClassNotFoundException {
232232
boolean derivedNewStatements = true;
233-
// System.out.println("在inferTransitivityStatements里头。");
233+
// System.out.println("��inferTransitivityStatements��ͷ��");
234234

235235
// We'll not use filesystem but db.getTransitiveStatementsCount()
236236
long derivation = 0;
@@ -242,7 +242,7 @@ private long inferTransitivityStatements(String[] args)
242242
//modified 2015/5/19
243243
//for(int i = 0;i <= 3; i++){
244244
while ((beforeInferCount > 0) && derivedNewStatements && shouldInferTransitivity) {
245-
// System.out.println("开始在inferTransitivityStatements的while循环中寻找。");
245+
// System.out.println("��ʼ��inferTransitivityStatements��whileѭ����Ѱ�ҡ�");
246246
level++;
247247

248248
//Configure input. Take only the directories that are two levels below
@@ -435,10 +435,10 @@ private long inferEquivalenceStatements(String[] args) throws IOException, Inter
435435
step++;
436436

437437
Set<Integer> filters = new HashSet<Integer>();
438-
filters.add(TriplesUtils.SCHEMA_TRIPLE_SUBCLASS);
439-
filters.add(TriplesUtils.SCHEMA_TRIPLE_SUBPROPERTY);
440-
filters.add(TriplesUtils.SCHEMA_TRIPLE_EQUIVALENT_CLASS);
441-
filters.add(TriplesUtils.SCHEMA_TRIPLE_EQUIVALENT_PROPERTY);
438+
// filters.add(TriplesUtils.SCHEMA_TRIPLE_SUBCLASS);
439+
// filters.add(TriplesUtils.SCHEMA_TRIPLE_SUBPROPERTY);
440+
// filters.add(TriplesUtils.SCHEMA_TRIPLE_EQUIVALENT_CLASS);
441+
// filters.add(TriplesUtils.SCHEMA_TRIPLE_EQUIVALENT_PROPERTY);
442442

443443
Job job = MapReduceReasonerJobConfig.createNewJob(
444444
OWLReasoner.class,

0 commit comments

Comments
 (0)