This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cookbook Name:: erlang R13B04 | |
# Recipe:: default | |
# Author:: Ward Bekker <[email protected]> | |
# | |
# Copyright 2008-2009, Joe Williams | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% autoload all modules that are in the code:path() and reside in the user directory | |
%% put in ~/.erlang | |
[code:ensure_loaded(list_to_atom(filename:rootname(filename:basename(F)))) | |
|| P <- lists:filter(fun(Path) -> string:str(Path, os:getenv("USER")) > 0 end, code:get_path()), F <- filelib:wildcard(P ++ "/*.beam")]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handle_call({import, FilePath}, _From, State) -> | |
{ok, Handle} = file:open(FilePath, [read, raw, binary]), | |
Position = 0, | |
Chunk = 1024, | |
CState = {Handle, Position, Chunk}, | |
{ok, _Result, _TrailingBytes} = | |
erlsom:parse_sax( | |
<<>>, | |
undefined, | |
fun(Event, _Acc) -> sax_event(Event) end, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sax_event({startElement, [] , "row", [], Attributes}) -> | |
{_,_,_,_,StringId} = lists:keyfind( "Id", 2, Attributes ), | |
Id = erlang:list_to_integer(StringId), | |
AttributesDict = lists:foldl( | |
fun( {attribute, AttributeName,_,_,AttributeValue}, AccIn )-> | |
dict:store(AttributeName, AttributeValue, AccIn) | |
end, | |
dict:new(), | |
Attributes), | |
CompleteAttributesDict = case dict:is_key("Title", AttributesDict) of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Eshell V5.8.1 (abort with ^G) | |
1> string:tokens("this is a test, thank you!", " ,!"). | |
["this","is","a","test","thank","you"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_attribute_tokens(Id, AttributeName, AttributeValue) -> | |
add_facet( Id, AttributeName, AttributeValue ), | |
Tokens = string:tokens(string:to_lower(AttributeValue), " ,.:;-"), | |
TokensAndPositions = lists:zip( Tokens, lists:seq( 1, length(Tokens))), | |
lists:foreach( | |
fun({Token, Position}) -> | |
keyword_ser:add_keyword_position( Token, Id, Position) | |
end, | |
TokensAndPositions | |
). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_facet(Id, "Tags", AttributeValue) -> | |
{match, Captured} = re:run(AttributeValue, "<(.*?)>", [global, {capture, all_but_first, list}]), | |
lists:foreach( fun(Match) -> facet_ser:add_facet_value( "Tags", Match, Id) end, Captured); | |
add_facet(Id, "CreationDate", AttributeValue) -> | |
[ Date | _Time ] = string:tokens(AttributeValue, "T"), | |
facet_ser:add_facet_value("CreationDate", Date, Id); | |
add_facet(_,_,_) -> | |
ignore. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_keyword_position(Keyword, DocCatId, Position) -> | |
Server = get_keyword_server( Keyword ), | |
gen_server:cast(Server, {add, DocCatId, Position}). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_keyword_server(Keyword) -> | |
ServerName = keyword_server_name(Keyword), | |
ServerProcessName = list_to_atom(ServerName), | |
case whereis(ServerProcessName) of | |
undefined -> | |
{ok, Pid} = supervisor:start_child(keyword_sup, [ServerProcessName]); | |
Pid -> | |
Pid | |
end, | |
Pid. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keyword_server_name(Keyword) -> | |
integer_to_list( | |
erlang:phash2( | |
porter:stem( | |
string:to_lower(Keyword) | |
) | |
) | |
) ++ "_keyword_server". |