-
Notifications
You must be signed in to change notification settings - Fork 173
/
LexiconRelation.java
3655 lines (2761 loc) · 119 KB
/
LexiconRelation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Copyright (C) SYSTAP, LLC 2006-2015. All rights reserved.
Contact:
SYSTAP, LLC
2501 Calvert ST NW #106
Washington, DC 20008
licenses@systap.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Created on Jul 4, 2008
*/
package com.bigdata.rdf.lexicon;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.log4j.Logger;
import org.omg.CORBA.portable.ValueFactory;
import org.openrdf.model.BNode;
import org.openrdf.model.Literal;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import com.bigdata.bop.BOp;
import com.bigdata.bop.IBindingSet;
import com.bigdata.bop.IPredicate;
import com.bigdata.bop.IVariableOrConstant;
import com.bigdata.bop.ap.Predicate;
import com.bigdata.btree.IIndex;
import com.bigdata.btree.IRangeQuery;
import com.bigdata.btree.ITuple;
import com.bigdata.btree.ITupleSerializer;
import com.bigdata.btree.IndexMetadata;
import com.bigdata.btree.IndexTypeEnum;
import com.bigdata.btree.filter.PrefixFilter;
import com.bigdata.btree.filter.TupleFilter;
import com.bigdata.btree.keys.IKeyBuilder;
import com.bigdata.btree.keys.KVO;
import com.bigdata.cache.ConcurrentWeakValueCacheWithBatchedUpdates;
import com.bigdata.journal.IIndexManager;
import com.bigdata.journal.IResourceLock;
import com.bigdata.journal.ITx;
import com.bigdata.journal.NoSuchIndexException;
import com.bigdata.journal.TimestampUtility;
import com.bigdata.rawstore.Bytes;
import com.bigdata.rdf.internal.IDatatypeURIResolver;
import com.bigdata.rdf.internal.IExtensionFactory;
import com.bigdata.rdf.internal.IInlineURIFactory;
import com.bigdata.rdf.internal.ILexiconConfiguration;
import com.bigdata.rdf.internal.IV;
import com.bigdata.rdf.internal.IVUtility;
import com.bigdata.rdf.internal.LexiconConfiguration;
import com.bigdata.rdf.internal.NoExtensionFactory;
import com.bigdata.rdf.internal.NoInlineURIFactory;
import com.bigdata.rdf.internal.NoSuchVocabularyItem;
import com.bigdata.rdf.internal.VTE;
import com.bigdata.rdf.internal.XSD;
import com.bigdata.rdf.internal.impl.BlobIV;
import com.bigdata.rdf.internal.impl.TermId;
import com.bigdata.rdf.internal.impl.bnode.SidIV;
import com.bigdata.rdf.internal.impl.extensions.XSDStringExtension;
import com.bigdata.rdf.model.BigdataBNode;
import com.bigdata.rdf.model.BigdataLiteral;
import com.bigdata.rdf.model.BigdataURI;
import com.bigdata.rdf.model.BigdataValue;
import com.bigdata.rdf.model.BigdataValueFactory;
import com.bigdata.rdf.model.BigdataValueFactoryImpl;
import com.bigdata.rdf.model.BigdataValueSerializer;
import com.bigdata.rdf.rio.StatementBuffer;
import com.bigdata.rdf.spo.ISPO;
import com.bigdata.rdf.store.AbstractTripleStore;
import com.bigdata.rdf.vocab.NoVocabulary;
import com.bigdata.rdf.vocab.Vocabulary;
import com.bigdata.relation.AbstractRelation;
import com.bigdata.relation.accesspath.AccessPath;
import com.bigdata.relation.accesspath.ArrayAccessPath;
import com.bigdata.relation.accesspath.EmptyAccessPath;
import com.bigdata.relation.accesspath.IAccessPath;
import com.bigdata.relation.locator.ILocatableResource;
import com.bigdata.relation.locator.IResourceLocator;
import com.bigdata.search.FullTextIndex;
import com.bigdata.service.IBigdataFederation;
import com.bigdata.striterator.ChunkedArrayIterator;
import com.bigdata.striterator.IChunkedOrderedIterator;
import com.bigdata.striterator.IKeyOrder;
import com.bigdata.util.CanonicalFactory;
import com.bigdata.util.NT;
import cutthecrap.utils.striterators.Resolver;
import cutthecrap.utils.striterators.Striterator;
/**
* The {@link LexiconRelation} handles all things related to the indices mapping
* external RDF {@link Value}s onto {@link IV}s (internal values)s and provides
* methods for efficient materialization of external RDF {@link Value}s from
* {@link IV}s.
*
* @author <a href="mailto:thompsonbry@users.sourceforge.net">Bryan Thompson</a>
* @version $Id$
*/
public class LexiconRelation extends AbstractRelation<BigdataValue>
implements IDatatypeURIResolver {
private final static Logger log = Logger.getLogger(LexiconRelation.class);
private final Set<String> indexNames;
private final List<IKeyOrder<BigdataValue>> keyOrders;
private final AtomicReference<IValueCentricTextIndexer<?>> viewRef = new AtomicReference<IValueCentricTextIndexer<?>>();
/**
* A new one for the subject-centric full text index.
*/
private final AtomicReference<ISubjectCentricTextIndexer<?>> viewRef2 = new AtomicReference<ISubjectCentricTextIndexer<?>>();
/**
* Note: This is a stateless class.
*/
private final BlobsIndexHelper h = new BlobsIndexHelper();
@SuppressWarnings("unchecked")
protected Class<BigdataValueFactory> determineValueFactoryClass() {
final String className = getProperty(
AbstractTripleStore.Options.VALUE_FACTORY_CLASS,
AbstractTripleStore.Options.DEFAULT_VALUE_FACTORY_CLASS);
final Class<?> cls;
try {
cls = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Bad option: "
+ AbstractTripleStore.Options.VALUE_FACTORY_CLASS, e);
}
if (!BigdataValueFactory.class.isAssignableFrom(cls)) {
throw new RuntimeException(
AbstractTripleStore.Options.VALUE_FACTORY_CLASS
+ ": Must implement: "
+ BigdataValueFactory.class.getName());
}
return (Class<BigdataValueFactory>) cls;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Class<IValueCentricTextIndexer> determineTextIndexerClass() {
final String className = getProperty(
AbstractTripleStore.Options.TEXT_INDEXER_CLASS,
AbstractTripleStore.Options.DEFAULT_TEXT_INDEXER_CLASS);
final Class<?> cls;
try {
cls = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Bad option: "
+ AbstractTripleStore.Options.TEXT_INDEXER_CLASS, e);
}
if (!IValueCentricTextIndexer.class.isAssignableFrom(cls)) {
throw new RuntimeException(
AbstractTripleStore.Options.TEXT_INDEXER_CLASS
+ ": Must implement: "
+ IValueCentricTextIndexer.class.getName());
}
return (Class<IValueCentricTextIndexer>) cls;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Class<ISubjectCentricTextIndexer> determineSubjectCentricTextIndexerClass() {
final String className = getProperty(
AbstractTripleStore.Options.SUBJECT_CENTRIC_TEXT_INDEXER_CLASS,
AbstractTripleStore.Options.DEFAULT_SUBJECT_CENTRIC_TEXT_INDEXER_CLASS);
final Class<?> cls;
try {
cls = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Bad option: "
+ AbstractTripleStore.Options.SUBJECT_CENTRIC_TEXT_INDEXER_CLASS, e);
}
if (!ISubjectCentricTextIndexer.class.isAssignableFrom(cls)) {
throw new RuntimeException(
AbstractTripleStore.Options.SUBJECT_CENTRIC_TEXT_INDEXER_CLASS
+ ": Must implement: "
+ ISubjectCentricTextIndexer.class.getName());
}
return (Class<ISubjectCentricTextIndexer>) cls;
}
@SuppressWarnings("unchecked")
protected Class<IExtensionFactory> determineExtensionFactoryClass() {
final String defaultClassName;
if (vocab == null || vocab.getClass() == NoVocabulary.class) {
/*
* If there is no vocabulary then you can not use the default
* extension class (or probably any extension class for that matter
* since the vocbulary is required in order to be able to resolve
* the URIs for the extension).
*
* @see https://sourceforge.net/apps/trac/bigdata/ticket/456
*/
defaultClassName = NoExtensionFactory.class.getName();
} else {
defaultClassName = AbstractTripleStore.Options.DEFAULT_EXTENSION_FACTORY_CLASS;
}
final String className = getProperty(
AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS,
defaultClassName);
final Class<?> cls;
try {
cls = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Bad option: "
+ AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS, e);
}
if (!IExtensionFactory.class.isAssignableFrom(cls)) {
throw new RuntimeException(
AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS
+ ": Must implement: "
+ IExtensionFactory.class.getName());
}
return (Class<IExtensionFactory>) cls;
}
@SuppressWarnings("unchecked")
protected Class<IInlineURIFactory> determineInlineURIFactoryClass() {
final String defaultClassName;
if (vocab == null || vocab.get(XSD.IPV4) == null) {
/*
* If there is no vocabulary then you can not use an inline URI
* factory because the namespaces must be in the vocabulary. If the
* XSD.IPV4 uri is not present in the vocabulary then either you are
* using NoVocabulary.class or an older version of the vocabulary
* that does not have that URI in it. Newer journals should be using
* DefaultBigdataVocabulary.
*/
defaultClassName = NoInlineURIFactory.class.getName();
} else {
defaultClassName = AbstractTripleStore.Options.DEFAULT_INLINE_URI_FACTORY_CLASS;
}
final String className = getProperty(
AbstractTripleStore.Options.INLINE_URI_FACTORY_CLASS,
defaultClassName);
final Class<?> cls;
try {
cls = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Bad option: "
+ AbstractTripleStore.Options.INLINE_URI_FACTORY_CLASS, e);
}
if (!IInlineURIFactory.class.isAssignableFrom(cls)) {
throw new RuntimeException(
AbstractTripleStore.Options.INLINE_URI_FACTORY_CLASS
+ ": Must implement: "
+ IInlineURIFactory.class.getName());
}
return (Class<IInlineURIFactory>) cls;
}
/**
* Note: The term:id and id:term indices MUST use unisolated write operation
* to ensure consistency without write-write conflicts. The only exception
* would be a read-historical view.
*
* @param indexManager
* @param namespace
* @param timestamp
* @param properties
*
*/
public LexiconRelation(final IIndexManager indexManager,
final String namespace, final Long timestamp,
final Properties properties) {
this(null/* container */, indexManager, namespace, timestamp,
properties);
}
public LexiconRelation(final AbstractTripleStore container,
final IIndexManager indexManager, final String namespace,
final Long timestamp, final Properties properties) {
super(container, indexManager, namespace, timestamp, properties);
{
this.textIndex = Boolean.parseBoolean(getProperty(
AbstractTripleStore.Options.TEXT_INDEX,
AbstractTripleStore.Options.DEFAULT_TEXT_INDEX));
if (textIndex) {
/*
* Explicitly disable overwrite for the full text index associated
* with the lexicon. By default, the full text index will replace
* the existing tuple for a key. We turn this property off because
* the RDF values are immutable as is the mapping from an RDF value
* to a term identifier. Hence if we observe the same key there is
* no need to update the index entry - it will only cause the
* journal size to grow but will not add any information to the
* index.
*/
properties
.setProperty(FullTextIndex.Options.OVERWRITE, "false");
// /*
// * Explicitly set the class which knows how to handle IVs in the
// * keys of the full text index.
// */
// properties.setProperty(
// FullTextIndex.Options.DOCID_FACTORY_CLASS,
// IVDocIdExtension.class.getName());
}
// just for now while I am testing, don't feel like rebuilding
// the entire journal
this.subjectCentricTextIndex = textIndex;
// this.subjectCentricTextIndex = Boolean.parseBoolean(getProperty(
// AbstractTripleStore.Options.SUBJECT_CENTRIC_TEXT_INDEX,
// AbstractTripleStore.Options.DEFAULT_SUBJECT_CENTRIC_TEXT_INDEXER_CLASS));
}
this.storeBlankNodes = Boolean.parseBoolean(getProperty(
AbstractTripleStore.Options.STORE_BLANK_NODES,
AbstractTripleStore.Options.DEFAULT_STORE_BLANK_NODES));
final int blobsThreshold;
{
blobsThreshold = Integer.parseInt(getProperty(
AbstractTripleStore.Options.BLOBS_THRESHOLD,
AbstractTripleStore.Options.DEFAULT_BLOBS_THRESHOLD));
if (blobsThreshold < 0 || blobsThreshold > 4 * Bytes.kilobyte) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.BLOBS_THRESHOLD + "="
+ blobsThreshold);
}
}
{
if (indexManager instanceof IBigdataFederation<?>
&& ((IBigdataFederation<?>) indexManager).isScaleOut()) {
final String defaultValue = AbstractTripleStore.Options.DEFAULT_TERMID_BITS_TO_REVERSE;
termIdBitsToReverse = Integer.parseInt(getProperty(
AbstractTripleStore.Options.TERMID_BITS_TO_REVERSE,
defaultValue));
if (termIdBitsToReverse < 0 || termIdBitsToReverse > 31) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.TERMID_BITS_TO_REVERSE
+ "=" + termIdBitsToReverse);
}
} else {
// Note: Not used in standalone.
termIdBitsToReverse = 0;
}
}
{
final Set<String> set = new HashSet<String>();
set.add(getFQN(LexiconKeyOrder.TERM2ID));
set.add(getFQN(LexiconKeyOrder.ID2TERM));
set.add(getFQN(LexiconKeyOrder.BLOBS));
if(textIndex) {
set.add(getNamespace() + "." + FullTextIndex.NAME_SEARCH);
}
// @todo add names as registered to base class? but then how to
// discover? could be in the global row store.
this.indexNames = Collections.unmodifiableSet(set);
this.keyOrders = Arrays
.asList((IKeyOrder<BigdataValue>[]) new IKeyOrder[] { //
LexiconKeyOrder.TERM2ID,//
LexiconKeyOrder.ID2TERM,//
LexiconKeyOrder.BLOBS //
});
}
/*
* Note: I am deferring resolution of the indices to minimize the
* latency and overhead required to "locate" the relation. In scale out,
* resolving the index will cause a ClientIndexView to spring into
* existence for the appropriate timestamp, and we often do not need
* that view for each index of the relation during query.
*/
// /*
// * cache hard references to the indices.
// */
//
// terms = super.getIndex(LexiconKeyOrder.TERM2ID);
//
// if(textIndex) {
//
// getSearchEngine();
//
// }
/*
* Lookup/create value factory for the lexicon's namespace.
*
* Note: The same instance is used for read-only tx, read-write tx,
* read-committed, and unisolated views of the lexicon for a given
* triple store.
*/
// valueFactory = BigdataValueFactoryImpl.getInstance(namespace);
try {
final Class<BigdataValueFactory> vfc = determineValueFactoryClass();
final Method gi = vfc.getMethod("getInstance", String.class);
this.valueFactory = (BigdataValueFactory) gi.invoke(null, namespace);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.VALUE_FACTORY_CLASS, e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.VALUE_FACTORY_CLASS, e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.VALUE_FACTORY_CLASS, e);
}
/*
* @todo This should be a high concurrency LIRS or similar cache in
* order to prevent the cache being flushed by the materialization of
* low frequency terms.
*/
{
final int termCacheCapacity = Integer.parseInt(getProperty(
AbstractTripleStore.Options.TERM_CACHE_CAPACITY,
AbstractTripleStore.Options.DEFAULT_TERM_CACHE_CAPACITY));
final Long commitTime = getCommitTime();
if (commitTime != null && TimestampUtility.isReadOnly(timestamp)) {
/*
* Shared for read-only views from sample commit time. Sharing
* allows us to reuse the same instances of the term cache for
* queries reading from the same commit point. The cache size is
* automatically increased to take advantage of the fact that it
* is a shared resource.
*
* Note: Sharing is limited to the same commit time to prevent
* life cycle issues across drop/create sequences for the triple
* store.
*/
termCache = termCacheFactory.getInstance(new NT(namespace,
commitTime.longValue()), termCacheCapacity * 2);
} else {
/*
* Unshared for any other view of the triple store.
*/
termCache = new TermCache<IV<?,?>, BigdataValue>(//
new ConcurrentWeakValueCacheWithBatchedUpdates<IV<?,?>, BigdataValue>(//
termCacheCapacity, // queueCapacity
.75f, // loadFactor (.75 is the default)
16 // concurrency level (16 is the default)
));
}
}
{
inlineLiterals = Boolean.parseBoolean(getProperty(
AbstractTripleStore.Options.INLINE_XSD_DATATYPE_LITERALS,
AbstractTripleStore.Options.DEFAULT_INLINE_XSD_DATATYPE_LITERALS));
inlineTextLiterals = Boolean.parseBoolean(getProperty(
AbstractTripleStore.Options.INLINE_TEXT_LITERALS,
AbstractTripleStore.Options.DEFAULT_INLINE_TEXT_LITERALS));
maxInlineTextLength = Integer.parseInt(getProperty(
AbstractTripleStore.Options.MAX_INLINE_TEXT_LENGTH,
AbstractTripleStore.Options.DEFAULT_MAX_INLINE_STRING_LENGTH));
inlineBNodes = storeBlankNodes && Boolean.parseBoolean(getProperty(
AbstractTripleStore.Options.INLINE_BNODES,
AbstractTripleStore.Options.DEFAULT_INLINE_BNODES));
inlineDateTimes = Boolean.parseBoolean(getProperty(
AbstractTripleStore.Options.INLINE_DATE_TIMES,
AbstractTripleStore.Options.DEFAULT_INLINE_DATE_TIMES));
inlineDateTimesTimeZone = TimeZone.getTimeZone(getProperty(
AbstractTripleStore.Options.INLINE_DATE_TIMES_TIMEZONE,
AbstractTripleStore.Options.DEFAULT_INLINE_DATE_TIMES_TIMEZONE));
rejectInvalidXSDValues = Boolean.parseBoolean(getProperty(
AbstractTripleStore.Options.REJECT_INVALID_XSD_VALUES,
AbstractTripleStore.Options.DEFAULT_REJECT_INVALID_XSD_VALUES));
// Resolve the vocabulary.
vocab = getContainer().getVocabulary();
final IExtensionFactory xFactory;
try {
/*
* Setup the extension factory.
*/
final Class<IExtensionFactory> xfc =
determineExtensionFactoryClass();
xFactory = xfc.newInstance();
} catch (InstantiationException e) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS, e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS, e);
}
final IInlineURIFactory uriFactory;
try {
/*
* Setup the inline URI factory.
*/
final Class<IInlineURIFactory> urifc =
determineInlineURIFactoryClass();
uriFactory = urifc.newInstance();
uriFactory.init(vocab);
} catch (InstantiationException e) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.INLINE_URI_FACTORY_CLASS, e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(
AbstractTripleStore.Options.INLINE_URI_FACTORY_CLASS, e);
}
/*
* Setup the lexicon configuration.
*/
lexiconConfiguration = new LexiconConfiguration<BigdataValue>(
blobsThreshold,
inlineLiterals, inlineTextLiterals,
maxInlineTextLength, inlineBNodes, inlineDateTimes,
inlineDateTimesTimeZone,
rejectInvalidXSDValues, xFactory, vocab, valueFactory,
uriFactory);
}
}
/**
* The canonical {@link BigdataValueFactoryImpl} reference (JVM wide) for the
* lexicon namespace.
*/
public BigdataValueFactory getValueFactory() {
return valueFactory;
}
final private BigdataValueFactory valueFactory;
/**
* Strengthens the return type.
*/
@Override
public AbstractTripleStore getContainer() {
return (AbstractTripleStore) super.getContainer();
}
public boolean exists() {
for(String name : getIndexNames()) {
if (getIndex(name) == null)
return false;
}
return true;
}
@Override
public LexiconRelation init() {
super.init();
/*
* Allow the extensions to resolve their datatype URIs into term
* identifiers.
*/
lexiconConfiguration.initExtensions(this);
return this;
}
@Override
public void create() {
final IResourceLock resourceLock = acquireExclusiveLock();
try {
super.create();
if (textIndex && inlineTextLiterals
&& maxInlineTextLength > (4 * Bytes.kilobyte32)) {
/*
* Log message if full text index is enabled and we are inlining
* textual literals and MAX_INLINE_TEXT_LENGTH is GT some
* threshold value (e.g., 4096). This combination represents an
* unreasonable configuration due to the data duplication in the
* full text index. (The large literals will be replicated
* within the full text index for each token extracted from the
* literal by the text analyzer.)
*/
log
.error("Configuration will duplicate large literals within the full text index"
+ //
": "
+ AbstractTripleStore.Options.TEXT_INDEX
+ "="
+ textIndex
+ //
", "
+ AbstractTripleStore.Options.INLINE_TEXT_LITERALS
+ "="
+ inlineTextLiterals
+ //
", "
+ AbstractTripleStore.Options.MAX_INLINE_TEXT_LENGTH
+ "=" + maxInlineTextLength//
);
}
final IIndexManager indexManager = getIndexManager();
// register the indices.
indexManager
.registerIndex(getTerm2IdIndexMetadata(getFQN(LexiconKeyOrder.TERM2ID)));
indexManager
.registerIndex(getId2TermIndexMetadata(getFQN(LexiconKeyOrder.ID2TERM)));
indexManager
.registerIndex(getBlobsIndexMetadata(getFQN(LexiconKeyOrder.BLOBS)));
if (textIndex) {
// Create the full text index
final IValueCentricTextIndexer<?> tmp = getSearchEngine();
tmp.create();
}
/*
* Note: defer resolution of the newly created index objects. This
* is mostly about efficiency since the scale-out API does not
* return the IIndex object when we register the index.
*/
// terms = super.getIndex(LexiconKeyOrder.TERMS);
// assert terms != null;
/*
* Allow the extensions to resolve their datatype URIs into term
* identifiers.
*/
lexiconConfiguration.initExtensions(this);
} finally {
unlock(resourceLock);
}
}
@Override
public void destroy() {
final IResourceLock resourceLock = acquireExclusiveLock();
try {
final IIndexManager indexManager = getIndexManager();
indexManager.dropIndex(getFQN(LexiconKeyOrder.TERM2ID));
indexManager.dropIndex(getFQN(LexiconKeyOrder.ID2TERM));
indexManager.dropIndex(getFQN(LexiconKeyOrder.BLOBS));
term2id = null;
id2term = null;
blobs = null;
if (textIndex) {
getSearchEngine().destroy();
viewRef.set(null);
}
// discard the value factory for the lexicon's namespace.
valueFactory.remove(/*getNamespace()*/);
termCache.clear();
super.destroy();
} finally {
unlock(resourceLock);
}
}
/** The reference to the TERM2ID index. */
volatile private IIndex term2id;
/** The reference to the ID2TERM index. */
volatile private IIndex id2term;
/** The reference to the TERMS index. */
volatile private IIndex blobs;
/**
* When <code>true</code> a full text index is maintained.
*
* @see AbstractTripleStore.Options#TEXT_INDEX
*/
private final boolean textIndex;
/**
* When <code>true</code> a secondary subject-centric full text index is
* maintained.
*
* @see AbstractTripleStore.Options#SUBJECT_CENTRIC_TEXT_INDEX
*/
private final boolean subjectCentricTextIndex;
/**
* When <code>true</code> the kb is using told blank nodes semantics.
*
* @see AbstractTripleStore.Options#STORE_BLANK_NODES
*/
private final boolean storeBlankNodes;
// /**
// * The maximum character length of an RDF {@link Value} before it will be
// * inserted into the {@link LexiconKeyOrder#BLOBS} index rather than the
// * {@link LexiconKeyOrder#TERM2ID} and {@link LexiconKeyOrder#ID2TERM}
// * indices.
// *
// * @see AbstractTripleStore.Options#BLOBS_THRESHOLD
// */
// private final int blobsThreshold;
/**
* @see AbstractTripleStore.Options#TERMID_BITS_TO_REVERSE
*/
private final int termIdBitsToReverse;
/**
* Are xsd datatype primitive and numeric literals being inlined into the statement indices.
*
* {@link AbstractTripleStore.Options#INLINE_XSD_DATATYPE_LITERALS}
*/
final private boolean inlineLiterals;
/**
* Are textual literals being inlined into the statement indices.
*
* {@link AbstractTripleStore.Options#INLINE_TEXT_LITERALS}
*/
final private boolean inlineTextLiterals;
/**
* The maximum length of <code>xsd:string</code> literals which will be
* inlined into the statement indices. The {@link XSDStringExtension} is
* registered when GT ZERO.
*/
final private int maxInlineTextLength;
/**
* Are bnodes being inlined into the statement indices.
*
* {@link AbstractTripleStore.Options#INLINE_BNODES}
*/
final private boolean inlineBNodes;
/**
* Are xsd:dateTime literals being inlined into the statement indices.
*
* {@link AbstractTripleStore.Options#INLINE_DATE_TIMES}
*/
final private boolean inlineDateTimes;
/**
* When <code>true</code>, XSD datatype literals which do not validate
* against their datatype will be rejected rather than inlined.
*
* {@link AbstractTripleStore.Options#REJECT_INVALID_XSD_VALUES}
*/
final private boolean rejectInvalidXSDValues;
/**
* The default time zone to be used for decoding inline xsd:datetime
* literals from the statement indices. Will use the current timezeon
* unless otherwise specified using
* {@link AbstractTripleStore.Options#DEFAULT_INLINE_DATE_TIMES_TIMEZONE}.
*/
final private TimeZone inlineDateTimesTimeZone;
/**
* Return <code>true</code> if datatype literals are being inlined into
* the statement indices.
*/
final public boolean isInlineLiterals() {
return inlineLiterals;
}
/**
* Return the maximum length a string value which may be inlined into the
* statement indices.
*/
final public int getMaxInlineStringLength() {
return maxInlineTextLength;
}
/**
* Return <code>true</code> if xsd:datetime literals are being inlined into
* the statement indices.
*/
final public boolean isInlineDateTimes() {
return inlineDateTimes;
}
/**
* Return the default time zone to be used for inlining.
*/
final public TimeZone getInlineDateTimesTimeZone() {
return inlineDateTimesTimeZone;
}
/**
* The #of low bits from the term identifier that are reversed and
* rotated into the high bits when it is assigned.
*
* @see AbstractTripleStore.Options#TERMID_BITS_TO_REVERSE
*/
final public int getTermIdBitsToReverse() {
return termIdBitsToReverse;
}
/**
* <code>true</code> iff blank nodes are being stored in the lexicon's
* forward index.
*
* @see AbstractTripleStore.Options#STORE_BLANK_NODES
*/
final public boolean isStoreBlankNodes() {
return storeBlankNodes;
}
/**
* <code>true</code> iff the (value centric) full text index is enabled.
*
* @see AbstractTripleStore.Options#TEXT_INDEX
*/
final public boolean isTextIndex() {
return textIndex;
}
/**
* <code>true</code> iff the subject-centric full text index is enabled.
*
* @see AbstractTripleStore.Options#SUBJECT_CENTRIC_TEXT_INDEX
*/
final public boolean isSubjectCentricTextIndex() {
return subjectCentricTextIndex;
}
/**
* Overridden to use local cache of the index reference.
*/
@Override
public IIndex getIndex(final IKeyOrder<? extends BigdataValue> keyOrder) {
if (keyOrder == LexiconKeyOrder.ID2TERM) {
return getId2TermIndex();