<commit_before>from rdflib import *
from rdflib.Graph import QuotedGraph

def term2Letter(term):
    if type(term) == URIRef:
        return 'U'
    elif type(term) == BNode:    
        return 'B'
    elif type(term) == Literal:
        return 'L'
    elif type(term) == QuotedGraph:
        return 'F'
    elif type(term) == Variable:
        return 'V'
    else:
        print term,type(term)
        raise

def triplePattern2termCombinations((s,p,o)):
    combinations=[]
    #combinations.update(TERM_COMBINATIONS)
    if type(o)==Literal:
        for key,val in TERM_COMBINATIONS.items():
            if key[OBJECT] == 'O':
                combinations.append(val)
    return combinations
    
def type2TermCombination(member,klass):
    return TERM_COMBINATIONS['%sU%s'%(term2Letter(member),term2Letter(klass))]

def statement2TermCombination(subject,predicate,obj):
    #print subject,predicate,obj
    rt=TERM_COMBINATIONS['%s%s%s'%(term2Letter(subject),term2Letter(predicate),term2Letter(obj))]
    #print rt
    return rt

SUBJECT = 0
PREDICATE = 1<commit_msg>added term instanciation dictionary and added use of isinstance instead of type (better performance)<commit_after>from rdflib import *
from rdflib.Graph import QuotedGraph

TERM_INSTANCIATION_DICT ={
    'U':URIRef,
    'B':BNode,
    'V':Variable,
}




def term2Letter(term):
    if isinstance(term,URIRef):
        return 'U'
    elif isinstance(term,BNode):    
        return 'B'
    elif isinstance(term,Literal):
        return 'L'
    elif isinstance(term,QuotedGraph):
        return 'F'
    elif isinstance(term,Variable):
        return 'V'
    else:
        print term,type(term)
        raise

def triplePattern2termCombinations((s,p,o)):
    combinations=[]
    #combinations.update(TERM_COMBINATIONS)
    if isinstance(o,Literal):
        for key,val in TERM_COMBINATIONS.items():
            if key[OBJECT] == 'O':
                combinations.append(val)
    return combinations
    
def type2TermCombination(member,klass):
    return TERM_COMBINATIONS['%sU%s'%(term2Letter(member),term2Letter(klass))]

def statement2TermCombination(subject,predicate,obj):
    #print subject,predicate,obj
    rt=TERM_COMBINATIONS['%s%s%s'%(term2Letter(subject),term2Letter(predicate),term2Letter(obj))]
    #print rt
    return rt

SUBJECT = 0
PREDICATE = 1
{'fraction_non_alphanumeric': 0.1154011154011154, 'fraction_numerical': 0.009438009438009438, 'mean_word_length': 3.467432950191571, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6061267', 'n_tokens_mistral': 809, 'n_tokens_neox': 765, 'n_words': 153}