<commit_before>''' -- imports from python libraries -- '''
# import os -- Keep such imports here
import json
import subprocess

''' -- imports from installed packages -- '''
from django.shortcuts import render_to_response  # , render
from django.template import RequestContext
from django.http import Http404, HttpResponse

try:
    from bson import ObjectId
except ImportError:  # old pymongo
    from pymongo.objectid import ObjectId


''' -- imports from application folders/files -- '''
from gnowsys_ndf.ndf.models import node_collection, triple_collection, gridfs_collection, NodeJSONEncoder

def query_doc(request, doc_id_or_name=None):

	if ObjectId.is_valid(doc_id_or_name):
		doc_id_or_name = ObjectId(doc_id_or_name)

	query_res = node_collection.find({
								'$or': [
										{'_id': doc_id_or_name},
										{'name': unicode(doc_id_or_name)}
									]
								})

	result = []
	for each_doc in query_res:
		result.append(json.dumps(each_doc, cls=NodeJSONEncoder, sort_keys=True))

	return render_to_response('ndf/dev_query_doc.html',
					        {'result': result},
					        context_instance=RequestContext(request)
						    )


def render_test_template(request):
	test_node = node_collection.one({"name":"home",'_type':"Group"})
	return render_to_response(
        'ndf/test_template.html',
        {"node":test_node},
        context_instance=RequestContext(request)
    )


def git_branch(request):
	return HttpResponse(subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']),
		content_type="text/plain")
	
def git_misc(request, git_command):
	response = "Unsupported"<commit_msg>updated query_doc function to take nbh input and render NBH of node<commit_after>''' -- imports from python libraries -- '''
# import os -- Keep such imports here
import json
import subprocess

''' -- imports from installed packages -- '''
from django.shortcuts import render_to_response  # , render
from django.template import RequestContext
from django.http import Http404, HttpResponse

try:
    from bson import ObjectId
except ImportError:  # old pymongo
    from pymongo.objectid import ObjectId


''' -- imports from application folders/files -- '''
from gnowsys_ndf.ndf.models import node_collection, triple_collection, gridfs_collection, NodeJSONEncoder

def query_doc(request, doc_id_or_name=None, option=None):

	if ObjectId.is_valid(doc_id_or_name):
		doc_id_or_name = ObjectId(doc_id_or_name)

	query_res = node_collection.find({
								'$or': [
										{'_id': doc_id_or_name},
										{'name': unicode(doc_id_or_name)}
									]
								})

	result = []
	for each_doc in query_res:
		if option in ['nbh', 'NBH', 'get_neighbourhood']:
			each_doc.get_neighbourhood(each_doc.member_of)
		result.append(json.dumps(each_doc, cls=NodeJSONEncoder, sort_keys=True))

	return render_to_response('ndf/dev_query_doc.html',
					        {'result': result, 'query': doc_id_or_name, 'count': query_res.count()},
					        context_instance=RequestContext(request)
						    )


def render_test_template(request):
	test_node = node_collection.one({"name":"home", '_type':"Group"})
	return render_to_response(
        'ndf/test_template.html',
        {"node":test_node},
        context_instance=RequestContext(request)
    )


def git_branch(request):
	return HttpResponse(subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']),
		content_type="text/plain")
	
def git_misc(request, git_command):
	response = "Unsupported"
{'fraction_non_alphanumeric': 0.11876621504756414, 'fraction_numerical': 0.0017296050735082155, 'mean_word_length': 4.2023988005997, 'pattern_counts': {'":': 4, '<': 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': '4432582', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1083, 'n_words': 235}