# Path: csc/divisi/graphics.py
# def output_svg(u, filename, concepts=None, xscale=1000, yscale=1000, min=0):
#     if concepts is None: concepts = u.label_list(0)
#     out = open(filename, 'w')
#     try:
#         print >> out, svg_header
#         diamonds = []
#         for concept in concepts:
#             x, y = u[concept, 0], u[concept, 1]
#             diamonds.append(svg_diamond(x*xscale+350, y*yscale+450,
#             make_color(u[concept, 2], u[concept, 3], u[concept, 4])))
#             if abs(x) > min or abs(y) > min:
#                 print >> out, svg_text(x*xscale+350, y*yscale+450, xmlspecialchars(concept)).encode('utf-8')
#         print >> out, '\n'.join(diamonds).encode('utf-8')
#         print >> out, svg_footer
#     finally:
#         out.close()


import sys, pickle, os
from csc.divisi.cnet import *
from csc.divisi.graphics import output_svg
from vendor_db import iter_info
from csamoa.corpus.models import *
from csamoa.conceptnet.models import *
        if check_concept(pair): windows.append(pair)
        if check_concept(words[x]): windows.append(words[x])
    for c in range(wsize-1):
        if check_concept(words[c]): windows.append(words[c])
    return windows

if 'vendor_only.pickle' in os.listdir('.'):
    print "Loading saved matrix."
    matrix = pickle.load(open("vendor_only.pickle"))
else:
    print "Creating New Tensor"
    matrix = SparseLabeledTensor(ndim=2)
    print "Adding Vendors"
    for co, englist in iter_info('CFB_Cities'):
        print co
        for phrase in englist:
            parts = english_window(phrase)
            print parts
            for part in parts:
                matrix[co, ('sells', part)] += factor
                matrix[part, ('sells_inv', co)] += factor
    pickle.dump(matrix, open("vendor_only.pickle", 'w'))

print "Normalizing."
matrix = matrix.normalized()

print "Matrix constructed. Running SVD."
svd = matrix.svd(k=10)
svd.summarize()


# Path: csc/divisi/graphics.py
# def output_svg(u, filename, concepts=None, xscale=1000, yscale=1000, min=0):
#     if concepts is None: concepts = u.label_list(0)
#     out = open(filename, 'w')
#     try:
#         print >> out, svg_header
#         diamonds = []
#         for concept in concepts:
#             x, y = u[concept, 0], u[concept, 1]
#             diamonds.append(svg_diamond(x*xscale+350, y*yscale+450,
#             make_color(u[concept, 2], u[concept, 3], u[concept, 4])))
#             if abs(x) > min or abs(y) > min:
#                 print >> out, svg_text(x*xscale+350, y*yscale+450, xmlspecialchars(concept)).encode('utf-8')
#         print >> out, '\n'.join(diamonds).encode('utf-8')
#         print >> out, svg_footer
#     finally:
#         out.close()


# Path: doc/demo/vendor_only_svd.py
import sys, pickle, os
from csc.divisi.cnet import *
from csc.divisi.graphics import output_svg
from vendor_db import iter_info
from csamoa.corpus.models import *
from csamoa.conceptnet.models import *

        if check_concept(pair): windows.append(pair)
        if check_concept(words[x]): windows.append(words[x])
    for c in range(wsize-1):
        if check_concept(words[c]): windows.append(words[c])
    return windows

if 'vendor_only.pickle' in os.listdir('.'):
    print "Loading saved matrix."
    matrix = pickle.load(open("vendor_only.pickle"))
else:
    print "Creating New Tensor"
    matrix = SparseLabeledTensor(ndim=2)
    print "Adding Vendors"
    for co, englist in iter_info('CFB_Cities'):
        print co
        for phrase in englist:
            parts = english_window(phrase)
            print parts
            for part in parts:
                matrix[co, ('sells', part)] += factor
                matrix[part, ('sells_inv', co)] += factor
    pickle.dump(matrix, open("vendor_only.pickle", 'w'))

print "Normalizing."
matrix = matrix.normalized()

print "Matrix constructed. Running SVD."
svd = matrix.svd(k=10)
svd.summarize()


output_svg(svd.u, "vendorplain.svg", xscale=3000, yscale=3000, min=0.03)