5656import java .util .HashSet ;
5757import java .util .Optional ;
5858import java .util .Set ;
59+ import java .util .concurrent .ConcurrentHashMap ;
5960import java .util .concurrent .locks .ReadWriteLock ;
6061import java .util .concurrent .locks .ReentrantReadWriteLock ;
6162import java .util .concurrent .locks .StampedLock ;
@@ -845,6 +846,8 @@ public long getId(Value value) throws IOException {
845846 return getId (value , false );
846847 }
847848
849+ private final ConcurrentHashMap <Value , Long > commonVocabulary = new ConcurrentHashMap <>();
850+
848851 /**
849852 * Gets the ID for the specified value.
850853 *
@@ -872,6 +875,9 @@ public long getId(Value value, boolean create) throws IOException {
872875 try {
873876 // Check cache
874877 Long cachedID = valueIDCache .get (value );
878+ if (cachedID == null ) {
879+ cachedID = commonVocabulary .get (value );
880+ }
875881
876882 if (cachedID != null ) {
877883 long id = cachedID ;
@@ -903,6 +909,11 @@ public long getId(Value value, boolean create) throws IOException {
903909 // Store id in cache
904910 LmdbValue nv = getLmdbValue (value );
905911 nv .setInternalID (id , revision );
912+
913+ if (nv .isIRI () && isCommonVocabulary (((IRI ) nv ))) {
914+ commonVocabulary .put (value , id );
915+ }
916+
906917 valueIDCache .put (nv , id );
907918 }
908919 }
@@ -916,6 +927,14 @@ public long getId(Value value, boolean create) throws IOException {
916927 return LmdbValue .UNKNOWN_ID ;
917928 }
918929
930+ private static boolean isCommonVocabulary (IRI nv ) {
931+ String string = nv .toString ();
932+ return string .startsWith ("http://www.w3.org/" ) ||
933+ string .startsWith ("http://purl.org/" ) ||
934+ string .startsWith ("http://publications.europa.eu/resource/authority" ) ||
935+ string .startsWith ("http://xmlns.com/" );
936+ }
937+
919938 public void gcIds (Collection <Long > ids , Collection <Long > nextIds ) throws IOException {
920939 if (!ids .isEmpty ()) {
921940 // wrap into read txn as resizeMap expects an active surrounding read txn
0 commit comments